1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Toggle avec style !</title>
<style>
body {
font-size: small;
font-family: sans-serif;
margin: 0;
padding: 0;
}
div.accordeon {
width: 20em;
border: solid thin white;
margin: 1.5em;
padding: 1em;
/* styles "whoaaaa" */
-moz-border-radius: 1ex;
-moz-box-shadow: gray 2px 4px 8px 0;
background: -moz-linear-gradient(white, #eee);
}
div.accordeon h3 {
cursor: pointer;
margin: 0;
}
div.accordeon div {
text-align: justify;
margin-top: 1em;
}
</style>
<script src="jquery-1.4.3.min.js"></script>
<script>
$(document).ready(function() {
$('div.accordeon > div').hide();
var h3Style = {
'font-family': 'serif',
'color': 'red',
'font-style': 'italic'
};
$('div.accordeon > h3').toggle(function() {
var $this = $(this);
if (!$this.data('oldStyle')) {
$this.data('oldStyle', {
'font-family': $this.css('font-family'),
'color': $this.css('color'),
'font-style': $this.css('font-style')
});
};
$this.css(h3Style);
var $nextDiv = $this.next();
var $visibleSiblings = $nextDiv.siblings('div:visible');
if ($visibleSiblings.length) {
$visibleSiblings.slideUp('fast', function() {
$nextDiv.slideDown('fast');
});
} else {
$nextDiv.slideDown('fast');
};
},
function() {
var $this = $(this);
$this.css($this.data('oldStyle'));
var $nextDiv = $this.next();
var $visibleSiblings = $nextDiv.siblings('div:visible');
if ($visibleSiblings.length) {
$visibleSiblings.slideUp('fast', function() {
$nextDiv.slideUp('fast');
});
} else {
$nextDiv.slideUp('fast');
};
});
});
</script>
</head>
<body>
<div class="accordeon">
<h3>Lorem</h3>
<div>Montius nos tumore inusitato quodam et novo ut rebellis et
maiestati recalcitrantes Augustae per haec quae strepit incusat iratus
nimirum quod contumacem praefectum, quid rerum ordo postulat ignorare
dissimulantem formidine tenus iusserim custodiri.</diV>
</div><!-- accordeon -->
</body>
</html> |
Partager