Bootstrap dropdown: events for the 'navbar-toggle'?

前端 未结 3 1795
长情又很酷
长情又很酷 2020-12-14 01:18

Do we have events for the navbar-toggle that appears when we are on the smaller screen?

For instance,

$(\'#myDropdown\'         


        
3条回答
  •  借酒劲吻你
    2020-12-14 01:33

    I couldn't get the show/shown or hide/hidden.bs.collapse events to be triggered. I tied the event to the #navbar element.

    What did work for me was just using the resize event and then check if the navbar is visible:

    Combining what @Patel, madhatter160 and @haxxxton suggested I was able to get it to work:

    var navbar_visible = $("#navbar").is(":visible");
    
    $(window).resize(function(){
      navbar_visible = $("#navbar").is(":visible");
    
      if (navbar_visible)
        $('#brand_name').text('Navbar is visible');
      else
        $('#brand_name').text('Navbar is not visible');
    });
    

    This is a pretty simple solution that doesn't need any special jQuery plugins to work. I wish it was possible to get this to work using the defined *.bs.collapse events though!

    You can also try this our on jsFiddle.

提交回复
热议问题