felo
April 8, 2020, 10:44pm
1
Hi, I have a one-page site with a menu on top. On mobile you can see the three lines to open the menu, but when you click one option it doesn't close so it cover a lot of the page, you have to close it manually. There is any way to auto-collapse the menu when i click a link?
My client is asking me for it.
Thank you!!
1 Like
saj
April 8, 2020, 11:00pm
2
@felo, you would need to create some JS that when you click the link in a mobile setting, it triggers the closing of the menu.
I think years back I created a quick little thing for someone so you may want to search for a similar article to find it.
Saj
felo
April 8, 2020, 11:17pm
3
thank you Saj. i will look for i it
marrco
April 9, 2020, 2:28pm
4
//Hamburger menu toggle
$(".navbar-nav li a").click(function (event) {
var toggle = $(".navbar-collapse").hasClass("show");
if (toggle) {
$(".navbar-toggler").click();
}
});
$('.navbar-nav > li > a').on('click', function() {
$('.navbar-collapse').collapse('hide');
});
$('.navbar-nav>li>a').on('click', function(){
$('.navbar-collapse').collapse('hide');
});
1 Like
felo
April 9, 2020, 5:18pm
5
thanks a lot. i use this post from Saj and it works fine!
https://bootstrapstudio.io/forums/topic/collapsed-navbar-wont-close-with-same-page-anchors/
Thank you!