Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  146] [ 5]  / answers: 1 / hits: 25676  / 10 Years ago, wed, october 15, 2014, 12:00:00

Please see my FIDDLE



I've got a 1 page website with a responsive navigation menu (with anchor links to elements on the page) that prepends to a menu icon when the browser viewport is smaller than a specific width (in my case 767px) using this javascript:



jQuery(document).ready(function($){
$('#menu_wrapper').prepend('<div id=menu-icon>Menu</div>');
$(#menu-icon).on(click, function(){
$(#menu).slideToggle();
$(this).toggleClass(active);
});
});


As you can see in the fiddle I'm also using javascript to make the navigation sticky when scrolling down past navigation element regardless of the viewport size.



Now the problem I have is that when I am below the viewport of 767px, I click on the toggle 'MENU' button to open / show the navigation and when I click an option in the menu, the page scrolls to the correct part of the page BUT the menu stays open.



What I want is the menu to close (slide back up) when an option is clicked in the menu (obviously this must only apply when I am below below the viewport of 767px).



How can I do this?


More From » jquery

 Answers
5

Just add this in $(document).ready function



$('#menu li').on('click', function(){
$(#menu).hide();
$(#menu-icon).removeClass(active);
});

[#69117] Monday, October 13, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dustin

Total Points: 599
Total Questions: 105
Total Answers: 106

Location: Belarus
Member since Tue, Mar 14, 2023
1 Year ago
dustin questions
;