tags:

views:

13

answers:

1

Hi All,

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

A: 

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

Nick Craver
@Nick, Thanks for your help, although your code makes the menu just fadeOut once clicked...is there a way of only having this happen when the DIV('.rtmenu') is showing? Thanks
Nasir
@Nasir - Only visible things can fade out, it'll ignore it otherwise...can you explain a bit more? I'm not quite following, the code posted should only fade out a `.rtmenu` if it's shown...what's different about behavior are you're after? That would help me see what you're wanting a bit better.
Nick Craver
Nasir
Nasir
I think I found a solution, just had to change 'click' to 'mousedown'...see here: $('.rtmenu').live('click', function(e) { e.stopImmediatePropagation(); }); $(document).mousedown(function() { $('.rtmenu').fadeOut(200); });
Nasir
@Nasir - Is there some other code acting on these elements that's not in the question?
Nick Craver