Twitter Bootstrap mobile nav: hide menu after clicking menu link

后端 未结 7 839
悲&欢浪女
悲&欢浪女 2020-12-15 05:56

I\'m looking for a way to make the Twitter Bootstrap mobile/tablet nav automatically hide/collapse after clicking a menu link. I have a lot of menu items and so when users e

7条回答
  •  失恋的感觉
    2020-12-15 06:07

    The navigation should be closed any time a user clicks anywhere on the body - not just navigation elements. Say menu is open, but user clicks in the page body. User expects to see menu close.

    You also have to make sure toggle button is visible, otherwise a jump is seen in menu.

    $(document).ready(function() { 
    
    $("body").click(function(event) {
            // only do this if navigation is visible, otherwise you see jump in navigation while collapse() is called 
             if ($(".navbar-collapse").is(":visible") && $(".navbar-toggle").is(":visible") ) {
                $('.navbar-collapse').collapse('toggle');
            }
      });
    
    });
    

提交回复
热议问题