Home › Forums › JavaScript › Collapsible Menu with Activ-State
- This topic is empty.
-
AuthorPosts
-
July 28, 2012 at 3:51 am #39111
dnnot
Memberhi everyone,
i`ve been looking now so long for a snippet of a collapsible menu with an active-state (arrow-up/arrow-down) – not an accordion menu, because i want to have more then one list-item open by clicking on the 2-3 available menus.Its like the “SNIPPETS”-area here on css-tricks only with an active state.
I hope someone can help me, i would be very thankful.sorry for bad english.
July 28, 2012 at 4:26 am #106922Taufik Nurrohman
Participant$(function() {
$('#accordion').children('[data-header]').hide().each(function() {
$(this).before('' + $(this).data('header') + '
');
}).prev().on("click", function() {
$(this).toggleClass('active').next().slideToggle();
});
});
Content 1
Content 2
Content 3
Content 4
Content 5
July 28, 2012 at 5:15 am #106923dnnot
Memberawesome, thank you!
July 28, 2012 at 8:30 am #106925dnnot
Memberhi again,
thanks for the help above – now i got a new problem : (
how i can include a persistence with jquery cookie?(with expire of as example 7 days)
i will be again very thankful for help!
July 28, 2012 at 8:43 am #106926agrimsrud
ParticipantHave a look at this plugin:
https://github.com/carhartl/jquery-cookie/July 28, 2012 at 12:58 pm #106933dnnot
Memberthank you for the help! but sorry i dont get it.
I tried to understand this, spend hours with google.. but nothing helped me.
July 28, 2012 at 1:43 pm #106934Taufik Nurrohman
ParticipantHere 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! :)
July 28, 2012 at 2:28 pm #106937dnnot
Memberyou are awesome, thank you for your great work!
but is it possible to prevent the animation (slideDown-Animation) if I refresh the page?July 29, 2012 at 1:03 am #106945Taufik Nurrohman
ParticipantChange
.slideDown()
to.show()
if (readCookie('expanded' + i)) {
// Just show the saved panel session
$(this).addClass('active').next().show();
}July 29, 2012 at 4:40 am #106954dnnot
Memberwow, finally everything works fine – you are my hero. thank you very much!
this community rocks.July 31, 2012 at 7:05 pm #107121scadole
MemberThank you for this tutorial!
I followed it to the tee and I only have 4 expanded boxes with content 1 to 5 listed. The menu isn’t collapsed and the headers are missing.
any ideas?
July 31, 2012 at 8:59 pm #107122Taufik Nurrohman
Participant@scadole: What version JQuery do you use? The above code, requiring a minimum of version 1.7
July 31, 2012 at 9:21 pm #107124scadole
MemberThanks for getting back to me…. 1.7 is the one i’m using. This is what it looks like now, and I can’t figure it out. http://lensspark.com/plays.html
August 1, 2012 at 2:34 am #107129scadole
MemberI changed the div h2 tag to an h2 and the content turned into an h2 style (which I didn’t want) but the headers all appeared and the collapsing worked. I changed the h2 tag back to a div and everything the content went back to the way it should have been and the collapsable headers stayed. I have know idea how or why, but certainly glad it worked. Thanks again for all your help. WOOOOHOOOOO!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.