Comments (9)
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.
from responsive-nav.js.
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
from responsive-nav.js.
Works great, thanks!
from responsive-nav.js.
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?
from responsive-nav.js.
@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();
});
});
from responsive-nav.js.
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.
from responsive-nav.js.
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!
from responsive-nav.js.
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', {
open: function(){
$('.nav-collapse a').click(function(){
nav.toggle();
});
}
});
Works a treat!
from responsive-nav.js.
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:
if ($(".nav-toggle").css("display") == "block" ){
nav.toggle();
}
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.
Reference: http://www.fourfront.us/blog/jquery-window-width-and-media-queries
More detailed example:
$('#myselector a').click(function (e) {
if ($(".nav-toggle").css("display") == "block" ){
nav.toggle();
}
});
from responsive-nav.js.
Related Issues (20)
- Navigation height with nested <ul> HOT 2
- responsiveNav is not defined HOT 2
- left nav cascaded
- Nav is buged
- closeOnNavClick variable changes location
- Multi-Level Responsive Nav
- Just a navigation. Clicking on navigation doesn't slide to anchor points?
- Checking if class exists
- Add opacity onScroll
- Support for Multi-level Nav HOT 1
- Appears from left or right
- Change hamburger to be an image so doesnt flash on page load
- Multilevel not opening on Android Chrome
- Using different customToggle when js-nav-active
- Plugin installation failed. (No valid plugins were found.)
- Nav not scrollable on dropdowns (where submenus available)
- Not working
- Unable to preventDefault inside passive event listener invocation. HOT 1
- How to initialize with a toggle?
- Explanation for installation process
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from responsive-nav.js.