Detecting when the mouse is not moving

后端 未结 7 725
逝去的感伤
逝去的感伤 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:27

    Yes, you have a onmousemove event in Javascript, so to achieve what you need you just have to do code something like this:

    startTimer();
    element.onmousemove = stopTimer(); //this stops and resets the timer
    

    You can use it on the document body tag for instance.

    UPDATE: @Marius has achieved a better example than this one.

提交回复
热议问题