On "PRODUCTS" click I slide up a white div (as seen in attached). When in responsive (mobile and tablet), I would like to automaticly close the responsive navbar and only show the white bar.
I tried:
$('.btn-navbar').click();
also tried:
$('.nav-collapse').toggle();
And it does work. However in desktop size, it is also called and does something funky to the menu where it shrinks for a second.
Any ideas?
You don't have to add any extra javascript to what's already included with bootstraps collapse option. Instead simply include data-toggle and data-target selectors on your menu list items just as you do with your navbar-toggle button. So for your Products menu item it would look like this
Then you would need to repeat the data-toggle and data-target selectors for each menu item
EDIT!!! In order to fix overflow issues and flickering on this fix I'm adding some more code that will fix this and still not have any extra javascript. Here is the new code:
Here it is at work http://jsfiddle.net/jaketaylor/84mqazgq/
This will make your toggle and target selectors specific to screen size and eliminate glitches on the larger menu. If anyone is still having issues with glitches please let me know and I'll find a fix. Thanks
EDIT: In the bootstrap v4.1.3 I couldnt use visible/hidden classes. Instead of
hidden-xs
used-none d-sm-block
and instead ofvisible-xs
used-block d-sm-none
.In the HTML I added a class of nav-link to the a tag of each navigation link.
Tuggle Nav Close, IE browser compatible answer, without any console error. If you are using bootstrap, use this