开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜