I am using few items in my bootstrap 3 navigation bar grouped in like below:
<nav class="navbar navbar-inverse navbar-fixed-top" id="toggleNav" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand name</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="javascript:logout();"><span class="glyphicon glyphicon-log-out"></span> Logout</a>
</li>
<li>
<a href="#" id="online-offline" toggle="offline"><span class="glyphicon glyphicon-off"></span> Go offline</a>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
When I click on the second item ('Go offline') I use jquery to invoke a modal window. On mobile I have to first collapse the menu to reach the link, and then when I click on that item I get my modal window correctly.
What I need to achieve is to hide the navbar collapse before showing the modal. Is it possible to programmatically toggle the navbar collapse? How can I do that ?
To create a collapsible navigation bar, use a button with class="navbar-toggler", data-toggle="collapse" and data-target="#thetarget" . Then wrap the navbar content (links, etc) inside a div element with class="collapse navbar-collapse" , followed by an id that matches the data-target of the button: "thetarget".
ml-auto class in Bootstrap can be used to align navbar items to the right. The . ml-auto class automatically aligns elements to the right.
Wrap both #nabar-mid-collapse and #navbar-rt-collapse in a div with class row-fluid , and apply class col-xs-4 (*or any respective . col class according to the width you need for each item *) to both of them. There is no row-fluid in Bootstrap 3.
As you said, the event will run a modal.
So, when your modal ( called yourModal ) is showing (before showing), just hide the menu :
JS :
$('.yourModal').on('show.bs.modal', function(){
$('.navbar-collapse').collapse('hide');
});
Here are the docs :
http://getbootstrap.com/javascript/#collapse
http://getbootstrap.com/javascript/#modals-usage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With