【发布时间】:2011-08-22 16:01:52
【问题描述】:
有没有办法检测鼠标指针停留在 html 元素上的秒数?
我想检索鼠标停留在元素上的秒数以对回调事件施加一点延迟...如果可能的话:)
我正在尝试通过计数器检测一个简单的 for() 循环:
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();
}
}
});
问题是它不起作用:(
我也想绑定一个mouseleave事件,脚本逻辑应该是:
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 }
【问题讨论】:
-
现在使用它:) 但似乎超时对我不起作用:P
-
$('.bean-active').live('mouseover',function(){ $(this).hoverIntent({ over: function(){ id_tag = $(this).attr ("id"); $(this).fadeTo(100,0.5).fadeTo(200,1); $('.bean-bubble,.bean-bubble img').hide(); $('#bean -bubble-'+id_tag+',#bean-bubble-'+id_tag+'img').show(); }, timeout:900, out: function(){ return false; } }); $(this).trigger ('鼠标悬停'); });
-
在没有鼠标离开的情况下可以计算秒数吗?因为我需要在三秒后加载数据而不是预加载数据。
标签: javascript jquery jquery-plugins mouseevent mouseover