Home › Forums › JavaScript › Collapsible Menu with Activ-State › Re: Collapsible Menu with Activ-State
July 28, 2012 at 1:43 pm
#106934
Participant
Here I use the standard JavaScript Cookie (I think):
$(function() {
$('#accordion').children('[data-header]').hide().each(function() {
$(this).before('' + $(this).data('header') + '
');
}).prev().each(function(i) {
$(this).on("click", function() {
if ($(this).next().is(':hidden')) {
$(this).addClass('active').next().slideDown();
createCookie('expanded' + i, null, 7); // Create a cookie named 'expanded-N' (N are: 0,1,2,3,blablablah...)
} else {
$(this).removeClass('active').next().slideUp();
eraseCookie('expanded' + i); // Or... delete the saved cookie (toggle)
}
});
// If the cookie named 'expanded-N' successfully read...
if (readCookie('expanded' + i)) {
// Slide down the saved panel session
$(this).addClass('active').next().slideDown();
}
});
});
Click some panel and then reload the page to see that the panel sessions can be stored: http://jsfiddle.net/tovic/EDQn9/12/
Hope this help! :)