Close offcanvas panel after click
Close the offcanvas panel after clicking on menu link
It may be a good usability option to close the offcanvas panel after clicking a menu link. This is very useful when used in conjunction with the scrollspy function.
1 - Follow the documentation and set up a navigation bar. Click here to see the Scrollspy tutorial.
2 - Use the code below to make this work:
Copy
var links = navigation.getElementsByClassName("navigation-link"); for(var i = 0; i < links.length; i++){ links[i].addEventListener("click", navigation.toggleOffcanvas); }
See the code working:
This code works with simple menu items (without submenus).
See the list of tutorials for other ways to modify the navigation bar and add features.