I have cobbled the below together in my (very) humble jQuery hackish way:
$(".toggle_container").hide();
$(".trigger a").addClass("close");
$(".trigger a").click(function() {
$(".toggle_container").slideUp('200','swing');
$(".trigger a").removeClass("open").addClass("close");
if ($(this).next(".toggle_container").is(":hidden")) {
$(this).next(".toggle_container").stop(true,false).slideToggle('200','swing');
}
});
jsfiddle is here: http://jsfiddle.net/FWzWu/8/
I have never used the jquery cookie plugin, but would like to use it now to remember the users menu state from page to page. Using the github plugin here: https://github.com/carhartl/jquery-cookie
Any help is most appreciated!
Thanks!
A first stab (I added a call to
event.preventDefault()to stop the default anchor action from happening on click – you may need to remove this).It could do with some cleaning up, for example it would be good to take advantage of event delegation to capture the click event on anchor elements, hopefully it conveys how to use the plugin and where to use it.
Obviously, this solution assumes that your containers are never going to change in number and order; if they do, the wrong container will end up being expanded on page load 🙂