Jquery: drop down menu wont disappear after clicking outside of menu

后端 未结 4 698
盖世英雄少女心
盖世英雄少女心 2020-12-30 17:02

I\'m new to jquery and I\'m looking at google\'s code to create their \'More\' button. I\'ve got it working atm but the only way to make the drop down disappear is to click

4条回答
  •  时光取名叫无心
    2020-12-30 17:10

    Bind a click event to html to capture any click made, and make it hide the menu

    $("html").click(function() {
      menu.find('.active').removeClass('active');
    });
    

    Then override that on your menu's click event using .stopPropagation();

    menu.find('ul li > a').bind('click', function (event) {
      event.stopPropagation();
    

    Fiddle: http://jsfiddle.net/rKaPN/12/

提交回复
热议问题