Mobile Menu - Click outside menu to close menu

后端 未结 2 1733
無奈伤痛
無奈伤痛 2021-01-23 09:24

\"enter

I have that button in my mobile website; the problem is, that I need to add a meth

相关标签:
2条回答
  • 2021-01-23 09:35

    Fiddle Link : http://jsfiddle.net/eAGjM/

    You'll need to check if the clicked portion is neither the Menu nor its child element. If your menu contains child element then this check is required otherwise clicking on sub elements will also hide the menu.

    $(document).mouseup(function(e){
       var menu = $('selector');
       if (!menu.is(e.target) // The target of the click isn't the container.
       && menu.has(e.target).length === 0) // Nor a child element of the container
       {
          menu.hide();
       }
    });
    
    0 讨论(0)
  • 2021-01-23 09:58

    You can do something like below to hide/close the menu

    $(document).click(function(){
     $(your class/id).hide('slow'); 
    });
    

    Here is Fiddle

    Instead of menu i have just shown a simple example for click

    0 讨论(0)
提交回复
热议问题