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
|
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="content-type">
<title></title>
<style>
.panel .contenu {
display:none;
}
.panel.expanded .contenu {
display:block;
position:absolute;
background: #CCC;
padding: 1em;
}
.panel .panel-toggle-btn:before {
content:"Ouvrir";
}
.panel.expanded .panel-toggle-btn:before {
content:"Fermer";
}
</style>
<script>
function expand($panelToOpen){
$(".panel").not($panelToOpen).removeClass("expanded");
$panelToOpen.toggleClass("expanded");
}
function init() {
var panelToExpand = 0; //déplie le premier panel par défaut
var match = window.location.hash.match(/expanded=(\d+)/);
if(match != null && match[1] != null){
panelToExpand = parseInt(match[1]);
}
expand( $(".panel").eq(panelToExpand) );
$(".panel").each(function(p){
$(this).find('.panel-toggle-btn').on('click', function(e){
e.preventDefault();
expand( $(this).closest('.panel') );
window.location.hash = "expanded="+p;
});
});
};
init();
</script>
</head>
<body>
<section class="panel">
<a class="panel-toggle-btn" href="#"></a>
<div class="contenu">
test1
</div>
</section>
<section class="panel">
<a class="panel-toggle-btn" href="#"></a>
<div class="contenu">
test2
</div>
</section>
<section class="panel">
<a class="panel-toggle-btn" href="#"></a>
<div class="contenu">
test3
</div>
</section>
</body>
</html> |