问题描述
有没有办法检测鼠标指针停留在html元素上的秒数?
is there any way to detect how many seconds a mouse pointer stays on an html element?
我想检索鼠标停留在元素上的秒数在回调事件上稍微延迟......如果可能的话:):
I would like to retrieve how many seconds a mouse stays over element to put a little delay on a callback event... if is possible :)
我正在尝试通过计数器检测一个简单的for()周期:
i'm trying with a simple for() cycle detecting by a counter :
var time_over ;
$('.bean-active').live('mouseover',function(){
id_tag = $(this).attr("id");
for(time_over = 1;time_over <= 3000;time_over ++){
if(time_over == 3000){
$('.bean-bubble,.bean-bubble img').hide();
$('#bean-bubble-'+id_tag+',#bean-bubble-'+id_tag+' img').show();
}
}
});
问题在于它不起作用:(
the problem is that it doesn't works :(
我也想绑定一个mouseleave事件,脚本逻辑应该是:
also i would like to bind a mouseleave event, script logic should be:
while ( mouseover element count how many time it stays over)
if (time == n)
{ do somenthing }
if (mouseleave from element earlier then time)
{ do somenthing different }
推荐答案
你应该能够利用悬停()
当鼠标移过特定元素时捕获的函数,然后在从该对象移除鼠标时根据需要做出反应。
You should be able to utilize the hover()
function to capture when the mouse goes over a particular element and then react as desired when the mouse is removed from that object.
$("#someDiv").hover(function(){
//start counter
}, function(){
//stop counter
});
这篇关于jQuery检测鼠标停留在元素上的秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!