You can use the timer to not trigger the hover action until you hover a certain amount of time like this, and then if the hover goes before the timer fires, you clear the timer, so nothing happens if you are just a short period of time:
$("img.badge").hover(function() { var timer = $(this).data("hover"); // if no timer set, set one otherwise if timer is already set, do nothing if (!timer) { // set timer that will fire the hover action after 2 seconds timer = setTimeout(function() { $("h3.better").stop(true).animate({"left": "125px"}, 1200); $(this).data("hover", null); }, 2000); // save timer $(this).data("hover", timer); } }, function() { var timer = $(this).data("hover"); if (timer) { clearTimeout(timer); $(this).data("hover", null); } else { // probably would be better to make this an absolute position rather // than a relative position $("h3.better").stop(true).animate({"left": "-500px"}, 800); } });
Note. I also added .stop(true) to your animation so that animations never accumulate.
jfriend00
source share