Do we have events for the navbar-toggle
that appears when we are on the smaller screen?
For instance,
$('#myDropdown').on('shown.bs.navbar-toggle', function () {
// do something…
});
$('#myDropdown').on('hide.bs.navbar-toggle', function () {
// do something…
});
html,
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-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="#">Home</a>-->
</div>
Otherwise, how can we detect if that navbar-toggle
exists on the smaller screen?
The navbar-toggle
methods emit the Collapse events:
Bootstrap's collapse class exposes a few events for hooking into collapse functionality.
Event Type Description
show.bs.collapse This event fires immediately when the show instance method is called.
shown.bs.collapse This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).
hide.bs.collapse This event is fired immediately when the hide method has been called.
hidden.bs.collapse This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to complete).
$('#myCollapsible').on('hidden.bs.collapse', function () {
// do something…
})