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
精彩评论