I pasted some code below of what seems to be a common approach to reveal a menu on mousemove. It seems that as the mouse continues to move, the duration of the timeout increases. What’s up with that? Is there a reason why the cleartimeout would not be working?
var timer;
$(document).mousemove(function() {
if (timer) {
clearTimeout(timer);
timer = 0;
}
$('.navi a, a.left, a.right').animate({top:'0px'},'fast');
timer = setTimeout(function() {
$('.navi a, a.left, a.right').animate({top:'50px'},'fast');
}, 1000)
});
problem is, you’re starting the animation to move up over and over again on each mousemove event. due to jquery’s animation queuing, every call to
animate()on the same object will get queued, so your your finalanimate()call in the delayed function (moving the element down again) has to wait until all ‘up’ animations are done.see this fiddle for a quick fix