flexnav
flexnav copied to clipboard
Close all open sub menus when user click another - Feature Request
Thank for creating this script - its great.
I've tried to change it do it does this, but my lack of JS knowledge has let me down again.
So basically I need to change it so that when the user clicks another dropdown arrow, all/any already open sub menus, should close.
A colleague has fixed this for me - is anyone interested in the code change? Shall I do a pull request?
Hi Juan, I would be interested in he code change. For me, this menu scarcely works... Everything stays open and the on over doesn't work either.
Hi juanfernandes, Can you please share your code example? Thanks, Michael
Fix -
$(window).on('resize', myResizer);
function myResizer() {
$(".flexnav ul").removeClass('flexnav-show').stop(true, true).hide();
}
That's not a fix for the problem codehandling?!
Can anyone post a real solution for closing all menu's when clicking another? \
I think he want a Accordion-Behavior which would be very useful. I also would be interested in a solution.
found it by myself with the code from codehandling:
add $(".flexnav ul").removeClass('flexnav-show').stop(true, true).hide(); to jquery.flexnav.js on line 120 (just under $('.touch-button').on('click', function(e) { )
That will close all tabs first, then open an other!
Even better solution. It slides up too:
Add
$(".flexnav ul").removeClass('flexnav-show').stop(true, true).slideUp(settings.animationSpeed);
after
else if ($sub.hasClass('flexnav-show') === false) {
or just replace the $('.touch-button').on('click', function(e) function with this:
$('.touch-button').on('click', function(e) { var $sub, $touchButton; $sub = $(this).parent('.item-with-ul').find('>ul'); $touchButton = $(this).parent('.item-with-ul').find('>span.touch-button'); if ($nav.hasClass('lg-screen') === true) { $(this).parent('.item-with-ul').siblings().find('ul.flexnav-show').removeClass('flexnav-show').hide(); } if ($sub.hasClass('flexnav-show') === true) { $sub.removeClass('flexnav-show').slideUp(settings.animationSpeed); return $touchButton.removeClass('active'); } else if ($sub.hasClass('flexnav-show') === false) { $(".flexnav ul").removeClass('flexnav-show').stop(true, true).slideUp(settings.animationSpeed); $sub.addClass('flexnav-show').slideDown(settings.animationSpeed); return $touchButton.addClass('active'); } });
What about if you have some submenus? It shouldn't close the parent if you clik on submenu.
didn't took a look at that. the website where I'm using the menu only has 1rst class childs, no submenus.
I'm not very good in jquery, but for submenu's the code needs to be rewritten... Maybe the original developer can help you / us?