即使鼠标仍然存在,jQuery mousemove()也会被调用 [英] jQuery mousemove() is called even if the mouse is still
本文介绍了即使鼠标仍然存在,jQuery mousemove()也会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对我来说,如果我尝试这个例子: http://jsfiddle.net/bY3CC/3/即使我将鼠标移动到文档上,然后我仍然可以看到鼠标移动文本。
为什么? ; \
另外,好像消息只出现在Chrome浏览器....
奇怪: -s
解决方案
全局事件
对象是非标准的,所以它只存在于一些浏览器中,比如IE(也许只有在怪癖模式下)以及在Chrome中出现。
接受event对象作为事件处理函数的参数:
var last_moved = 0;
$(document).mousemove(function(e){
var now = e.timeStamp;
if(now - last_moved> 1000){
$('#messages ').append('mouse moved< br />');
last_moved = now;
}
});
For me, if I try this example: http://jsfiddle.net/bY3CC/3/ the "mouse moved" text appears even if I move my mouse over the document and then I let it still...
Why's that? ;\
And also, seems like the message only appears in Chrome....
Strange :-s
解决方案
The global event
object is non-standard, so it only exists in some browsers, like IE (perhaps only in quirks mode) and appearently in Chrome.
Accept the event object as a parameter to the event handler:
var last_moved=0;
$(document).mousemove(function(e){
var now = e.timeStamp;
if (now - last_moved > 1000) {
$('#messages').append('mouse moved<br/>');
last_moved = now;
}
});
这篇关于即使鼠标仍然存在,jQuery mousemove()也会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文