开发者

How do I stop the fadeOut from triggering if menu is already open, using Jquery?

开发者 https://www.devze.com 2023-01-13 19:49 出处:网络
I\'m unsure why my code triggers the fadeOut() effect if the menu is already open? See code below: $(\'.rtmenu\').click(function(e) { e.stopPropagation(); });

I'm unsure why my code triggers the fadeOut() effect if the menu is already open? See code below:

$('.rtmenu').click(function(e) { e.stopPropagation(); });

$('.rtmenu').mouseout(function(){ 
     $(document).one('click',function() { $('.rtmenu').fadeOut(200); }); 
 })

Any help would be greatly appreciated开发者_如何学C


The code you have should work provided it's located inside a document.ready and the .rtmenu elements aren't being created dynamically. You can test it here.

If they're created dynamically, change it up a bit using a .live() handler and .stopImmediatePropagation(), like this:

$('.rtmenu').live('click', function(e) { e.stopImmediatePropagation(); });
$(document).click(function() { $('.rtmenu').fadeOut(200); });​

You can give it a try here

0

精彩评论

暂无评论...
验证码 换一张
取 消