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?
Bootstrap 4 solution without any Javascript
Add attributes
data-toggle="collapse" data-target="#navbarSupportedContent.show"
to the div<div class="collapse navbar-collapse">
Make sure you provide the correct
id
indata-target
just to be complete, in Bootstrap 4.0.0-beta using .show worked for me...
Not the newest thread but i searched for a solution for the same Problem and found one (a mix of some others).
I gave the NavButton:
an id / Identifier like:
Not the finest "Idea" - but: Works for me! Now you can check up the visibility of your button (with jquery) like:
(NOTE: This is just a Code snipped ! I used a "onclick" Event on my Nav Links! (Starting a AJAX Reguest.)
The result is: If the Button is "visible" it got "clicked" ... So: No Bug if you use the "Fullscreen view" of Bootstrap (width of over 940px).
Greetings Ralph
PS: It works fine with IE9, IE10 and Firefox 25. Didnt checked up others - But i can't see a Problem :-)
I really liked Jake Taylor's idea of doing it without additional JavaScript and taking advantage of Bootstrap's collapse toggle. I found you can fix the "flickering" issue present when the menu isn't in collapsed mode by modifying the
data-target
selector slightly to include thein
class. So it looks like this:I didn't test it with nested dropdowns/menus, so YMMV.
I'm assuming you have a line like this defining the nav area, based on Bootstrap examples and all
Simply add the properties as such, like on the MENU button
I've added to
<body>
as well, worked. Can't say I've profiled it or anything, but seems a treat to me...until you click on a random spot of the UI to open the menu, so not so good that.DK