我正在使用下面的javascript代码来检测500ms之后的鼠标停止间隔
document.onmousemove = (
var onmousestop = function() {
alert("mouse stopped moving");
}, thread;
return function() {
clearTimeout(thread);
thread = setTimeout(onmousestop, 500);
};
})();是否有一种方法可以检测鼠标停止移动多久,并执行代码,如果鼠标停止移动为500ms,任何帮助将不胜感激。提前谢谢..。:)
发布于 2013-11-15 08:39:11
我会使用这个插件,这是一个聪明有效的代码来跟踪鼠标停止事件。
http://richardscarrott.co.uk/posts/view/jquery-mousestop-event
例如,工作示例:http://jsfiddle.net/brunis/wLu4V/
$( 'html' ).bind('mousestop', function() {
// do timeout here
});
$( 'html' ).mousemove(function( event ) {
// clear timeout here
});我没有使用鼠标停止,你可以,如果你想,但它将需要一些额外的工作;鼠标停止只跟踪一个鼠标停止每鼠标。
如果您想使用mousestop事件插件,您可以很容易地只使用以下代码:
$.mousestopDelay = 500; // Wait 500 ms before triggering the mousestop event
$( 'html' ).bind('mousestop', function() {
alert("Mouse stop + 500 MS!");
});https://stackoverflow.com/questions/19996640
复制相似问题