New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close on click #39
Comments
I am also looking for exactly that. It does not feel natural to me if the menu stays open after a link was clicked. Is there any way to get done what @martinconnelly was asking for? Note: Request is for one page web design. On a design like that, the menu always stays open after a link was clicked. |
Just bump into this today and was struggling with that for a bit too. Not sure if you guys already got the solution, but for anyone who is interested. I would go at it with this short addition to the end of the script. All it does is triggering the toggle when any links in the menu is clicked. Basically, just add the function below $("#nav a").click(function(){navigation.toggle();}); within the Open callback option and it works like a charm |
Works great, thanks! |
I'm looking for exactly this solution, but, unfortunately, hvietphan's function isn't working for me. I've tried adding it in my in-page script as well as the original JS file, to no avail. Has anything changed in the last 3 mos that would have made this not work and, if so, is there a new solution? |
@angeliquejw Might be because @hvietphan's solution requires jQuery to work? without jQuery that would same code would be: [].forEach.call(document.querySelectorAll("#nav a"), function(el) {
el.addEventListener("click", function() {
navigation.toggle();
});
}); |
I couldn't get hvietphan's solution to work either unfortunately (with jQuery running). There's no navigation object as far as I can see so I'm not sure how to run the toggle method. |
Hi, thank you so much for this great script. I'm also trying to achieve closing the navigation upon clicking, or upon reaching the section that is linked. Any help you can provide would be appreciated. Thanks! |
I was having the same issue, using the script on a one page site. I just edited the script provided by @hvietphan. var nav = responsiveNav('.nav-collapse', { Works a treat! |
I had some false starts making the menu close only in mobile view, so here's working code for future vistors to this thread. In your click function:
Note that, rather than using screen width, I'm checking for a condition which is controlled by the media query. This is to avoid inconsistencies caused by whether or not the scrollbar is included. More detailed example:
|
First: Thanks. This is awesome.
I'm hoping there's a good and easy way to get the menu to toggle closed when you click li item. My guess is that that's what the public methods are for, but, that's a guess, and as far as it goes.
Many thanks again,
-m
The text was updated successfully, but these errors were encountered: