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?
This should do the trick.
Requires bootstrap.js.
Example => http://getbootstrap.com/javascript/#collapse
This does the same thing as adding 'data-toggle="collapse"' and 'href="yournavigationID"' attributes to navigation menus tags.
I'm using the mollwe function, although I added 2 improvements:
a) Avoid the dropdown closing if the link clicked is collapsed (including other links)
b) Hide the dropdown too, if you are clicking the visible web content.
This works, but does not animate.
if menu html is
on nav toggle 'in' class is added and removed from the toggle. check if responsive menu is opened then perform the close toggle.
I've got it to work with animation!
Menu in html:
Binding click event on all a elements in navigation to collapse menu (Bootstrap collapse plugin):
EDIT To make it more generic we can use following code snippet
If for example your toggle-able icon is visible only for extra small devices, then you could do something like this:
Clicking [data-toggle="offcanvas"] will add bootstrap's .hidden-xs to my #side-menu which will hide the side-menu content, but will become visible again if you increase the window size.