Is there any function in jquery that counts the time the mouse is over a div?
I'm using jquery and when i mouse over div A, div 开发者_如何学JAVAB appears.
What i would like to achieve is:
When the mouse is over div A greater than 3 seconds ( > 3s), the div B shall appear.
Is there any function in jquery that counts the time the mouse is over a div??
Thanks, in advance
var timer;
$('#diva')
.mouseenter(function () {
timer = setTimeout(function () { $('#divb').show(); }, 3000);
})
.mouseleave(function () {
clearTimeout(timer);
});
Upon entering #diva
, you start a timeout that will display #divb
after 3 seconds. Upon leaving #diva
, you cancel that timeout. As simple as that.
Just assign a timeout and clear it on mouseout:
var interval;
$("#over").hover(function(){
interval = window.setTimeout(function(){
$("#b").show();
},3000);
},function(){
window.clearTimeout(interval);
});
example: http://jsfiddle.net/3QGpA/1/
i don't think so..but you can achieve this by adding setTimeOut
in your hover
handler
精彩评论