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
| <!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="content-type">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<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 src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>function expand($panelToOpen){
$(".panel").not($panelToOpen).removeClass("expanded");
$panelToOpen.toggleClass("expanded");
}
function init() {
$(document).ready(function(){
var panelToExpand=4;//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;
});
});
});
};
</script>
</head>
<body>
<script>window.onload=init;</script>
<div class="panel">
<a class="panel-toggle-btn" href="#"></a>
<div class="contenu">
test1
</div>
</div>
<div class="panel">
<a class="panel-toggle-btn" href="#"></a>
<div class="contenu">
test2
</div>
</div>
<div class="panel">
<a class="panel-toggle-btn" href="#"></a>
<div class="contenu">
test3
</div>
</div>
</body>
</html> |