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

前端 未结 7 581
攒了一身酷
攒了一身酷 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-24 23:45

    Here is another approach which is working for me.

    My scenario: I want to hide the collapsible when I click anywhere outside of a form which contains a dropdownlist.

      $(document).ready(function(){
          //check if collapsible is shown
          $(".collapse").on('shown.bs.collapse', function(){
            //then check if there was a click
            $(document).click(function(event) {
              //exclude the click was on the form 
              if (!$(event.target).hasClass("input-default")) {
                  //then hide it
                  $(".collapse").collapse('hide');
              }
            });
          });
      });
    

提交回复
热议问题