Detecting when the mouse is not moving

后端 未结 7 722
逝去的感伤
逝去的感伤 2021-01-31 05:06

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.

7条回答
  •  天涯浪人
    2021-01-31 05:16

    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);
    }
    

提交回复
热议问题