When using bootstraps default navbar: http://getbootstrap.com/components/#navbar, the menu will not collapse automatically, when selecting a menu item.
I want to change this behaviour with the following code:
$(document).ready(function(){
var activatableButtons = $('.nav.navbar-nav a'),
navbar = $('#bs-example-navbar-collapse-1');
activatableButtons.click(function(){
navbar.collapse('hide');
});
});
I am using:
I set up a jsfiddle: http://jsfiddle.net/Ludmilla/5c3supgt/
PROBLEM DESCRIPTION: animations seen when selecting a menu button.
seemingly the collapse state of the menu is toggled, when clicking the first and second time. After the two initial clicks everything works as expected - no more animations.
Q: how to set things up, so that the state after 2 clicks is present right at the start?
TEST 1:
no more animations - OK
TEST 2:
The solution was simple: just one extra line needed, to get things initialized properly:
$(document).ready(function(){
var activatableButtons = $('.nav.navbar-nav a'),
navbar = $('#bs-example-navbar-collapse-1');
// this extra line fixes the problem:
navbar.collapse({toggle: false});
activatableButtons.click(function(){
navbar.collapse('hide');
});
});