Is there a way to trigger a mouseover event only after the mouse was hovering for 1 sec on an element?
$("img").mouseover(function () {
$(this).animate( {opacity:1}, 200);
});
Is there a way to trigger a mouseover event only after the mouse was hovering for 1 sec on an element?
$("img").mouseover(function () {
$(this).animate( {opacity:1}, 200);
});
$("img").on("mouseover mouseout", function() {
var tid = 0;
return function(e) {
var elem = $(this);
clearTimeout(tid);
if (e.type == "mouseover") {
tid = setTimeout(function() {
elem.stop(true).animate({
opacity: 1
}, 200);
}, 1000);
}
else {
console.log(elem);
elem.stop(true).animate({
opacity: 0.3
}, 200);
}
};
}());
You can use the hoverIntent() jQuery plugin found here: http://cherne.net/brian/resources/jquery.hoverIntent.html
Also, make sure you be careful when using these kinds of things as they do not work on mobile browsers or anything using a touch screen.
$("img").mouseover(function () {
$(this).delay(1000).animate( {opacity:1}, 200);
}).mouseleave(function() {
$(this).clearQueue().stop().animate({opacity:0.2},200);
});
You should use setTimeOut function.
setTimeOut(function(){$("img").mouseover(function () {
$(this).animate( {opacity:1}, 200);
});
},1000);
It takes time in milliseconds.
you can create a timer function (see [1]) that processes your event 1s later. You can store that function in an array or directly to "window", to let it be cancelable if "mouseout" occurs before the timer function triggers.