mrjasonweaver / flexnav

A jQuery plugin for responsive menus
The Unlicense
1.19k stars 393 forks source link

Close all open sub menus when user click another - Feature Request #149

Open juanfernandes opened 10 years ago

juanfernandes commented 10 years ago

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.

juanfernandes commented 10 years ago

A colleague has fixed this for me - is anyone interested in the code change? Shall I do a pull request?

vietnamsales commented 10 years ago

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.

Imonda commented 10 years ago

Hi juanfernandes, Can you please share your code example? Thanks, Michael

codehandling commented 10 years ago

Fix -

$(window).on('resize', myResizer);

function myResizer() {
    $(".flexnav ul").removeClass('flexnav-show').stop(true, true).hide();
}
behtjes commented 10 years ago

That's not a fix for the problem codehandling?!

Can anyone post a real solution for closing all menu's when clicking another? \

Kinky69 commented 10 years ago

I think he want a Accordion-Behavior which would be very useful. I also would be interested in a solution.

behtjes commented 10 years ago

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!

behtjes commented 10 years ago

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'); } });

marjanbajc commented 10 years ago

What about if you have some submenus? It shouldn't close the parent if you clik on submenu.

behtjes commented 10 years ago

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?