有没有一种方法可以在jquery中检测鼠标停止移动?
使用setTimeout,并在鼠标移动时清除它。如果鼠标在setTimeout指定的时间内没有移动,则可以假设鼠标已停止移动。利用jQuery,您可以这样做:
var stop_timeout = false;
$(function() {
$().mousemove(function() {
clearTimeout(stop_timeout);
stop_timeout = setTimeout(function() {
alert("The mouse has stopped.");
}, 1000);
});
});
每次鼠标移动时设置和取消超时时间有些繁琐,但它应该适合您的需求。