I have a video player page and want the playlist div to only fade in when the mouse is moving, and fade out if the mouse is idle for 3 seconds. The div's class is "fadeobject" and it's ID is ""video-chooser"
A:
Have a look at this
Jquery: how to make something fade out when mouse is idle. When mouse moves again, It fadesIn!
astander
2009-12-29 09:51:06
+1
A:
Assuming you mean the mouse moves anywhere and not just over the relevant <div>
apply a mousemove()
event handler to the page:
var fadeout = null;
$("html").mousemove(function() {
$("div.fadeobject").stop().fadeIn("slow");
if (fadeout != null) {
clearTimeout(fadeout);
}
fadeout = setTimeout(3000, hide_playerlist);
});
function hide_playlist() {
$("div.fadeobject").stop().fadeOut("slow");
}
Every time the mouse moves a timer is started to fade the div after three seconds and the previous timer (if there was one) is cancelled.
Note: the stop()
isn't strictly required here but is recommended when dealing with multiple animations/effects.
cletus
2009-12-29 09:51:39
No luck. (http://pastebin.com/f50026c62 apparently I cant put code in comments) am I missing something?Thanks for the help so far.
Stephen
2009-12-29 10:28:13