检测鼠标何时不移动 [英] Detecting when the mouse is not moving

查看:109
本文介绍了检测鼠标何时不移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以找到光标位置。但是我需要确定鼠标是否稳定。如果鼠标没有移动超过1分钟,那么我们必须提醒用户。

I am able to find the cursor position. But I need to find out if the mouse is stable. If the mouse wasn't moved for more than 1 minute, then we have to alert the user.

如何可能,有什么特殊的事件吗? (仅适用于JavaScript中的IE)

How its possible, are there any special events for this? (Only for IE in javascript)

推荐答案

将鼠标移动一分钟后设置超时,如果鼠标被移动,清除超时:

Set a timeout when the mouse is moved one minute into the future, and if the mouse is moved, clear the timeout:

var timeout;
document.onmousemove = function(){
  clearTimeout(timeout);
  timeout = setTimeout(function(){alert("move your mouse");}, 60000);
}

这篇关于检测鼠标何时不移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆