Bootstrap 3 Mobile nav won collapse when you click outside it

若如初见. 提交于 2019-12-10 18:44:27

问题


My Bootstrap 3 mobile menu does collapse when I click/touch outside the menu.

Ive can up with a solution to the problem:

$(document).on('touchstart click', 'html:not(nav)',function() {
 $(".navbar-collapse").removeClass("in");
});

However this doesn't collapse the same way as if you were to click the menu button. Please can somebody recommend a better solution.

Cheers Al


回答1:


$(document).on('click',function(){
  $('.navbar-collapse').collapse('hide');
})

Demo



来源:https://stackoverflow.com/questions/22749588/bootstrap-3-mobile-nav-won-collapse-when-you-click-outside-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!