View Single Post
Old 02-21-2013, 04:09 PM   PM User | #1
elem
New Coder

 
Join Date: Sep 2011
Posts: 35
Thanks: 18
Thanked 1 Time in 1 Post
elem is an unknown quantity at this point
Question jQuery fadeOut - how to delay and stop it if mouse enters again

Hi guys,

I've got a simple jQuery dropdown div, which fades in once you put your mouse over a certain button, and then fades away after the mouse is away. Since I don't like it to disappear instantly, I've put a delay on the fade out effect. It's all good, but my only problem appears when you move your mouse away and then move it back quickly, it would disappear and then appear again, instead of staying on all the time (I thought delay would stop the fade out effect from happening for that 1 sec, but it just ... delays it suprisingly lol).

So my quesiton is - how can I make that div stay for 1 second and not fade out if the mouse is back over it during that 1 second period? Here's my simple code:

Code:
$(".basket-preview").hide();
	$("#basket").mouseenter(function() {
		$(".basket-preview").fadeIn(300);	
	});
	$("#basket").mouseleave(function() {
		$(".basket-preview").delay(1000).fadeOut(300);
	});
elem is offline   Reply With Quote