How to hide my collapse bootstrap 3 navbar with click on body when, collapse is visible?

前端 未结 7 569
攒了一身酷
攒了一身酷 2021-01-24 23:39

I\'m making a WordPress website for agency where I will go work. I used Bootstrap 3.0, and I created a responsive menu.

How to hide menu when is collapsed and visible (

7条回答
  •  一整个雨季
    2021-01-25 00:10

    This is a functional solution:

    $(document).on('click touchstart', function (e) {
    if ($(e.target).closest(".navbar-collapse").length === 0 && $(e.target).closest('[data-target=".navbar-collapse"]').length === 0) {
        $(".navbar-toggle").collapse('hide');
    }
    });
    

提交回复
热议问题