Get the duration of continuous mouse movement

Elvin Jafali

Track the duration of continuous mouse movements on a webpage. A measurement begins when the cursor starts to move and ends when the cursor has stopped moving on the page. Reporting on duration happens thereafter. THis is what I have and works for while the mouse is moving and while it is stopped. However, I am confused how to track the start time and end time(i.e. the duration period of the mouse moving).

            var myDiv = document.getElementById("myDiv");
            var timeout;
            //var startTime;
            document.addEventListener("mousemove", function() {

                myDiv.innerHTML = "You are moving";
                if (timeout) clearTimeout(timeout);
                timeout = setTimeout(mouseStop, 150);
            });

            function mouseStop() {
                myDiv.innerHTML = "Stopped";
                //console.log(Math.abs((startTime.getTime() - endTime.getTime())/1000));
            }
joyBlanks

You can count time on a different timer thread. Once you stop rest the timer.

var myDiv = document.getElementById("myDiv");
var timeout;
var timer = {stopped: true, time: 0};

setInterval(() => {
  if (!timer.stopped) {
    timer.time++;
  }
}, 1000);

document.addEventListener("mousemove", function() {
  timer.stopped = false;
  myDiv.innerHTML = "You are moving";
  if (timeout) clearTimeout(timeout);
  timeout = setTimeout(mouseStop, 150);
});

function mouseStop() {
  var totalTime = timer.time;
  timer = {stopped: true, time: 0};
  myDiv.innerHTML = 'Stopped! Total time: ' + totalTime + ' seconds';
}
<div id="myDiv"></div>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Smooth mouse movement in C++

分類Dev

UWP + DirectX11: Mouse movement

分類Dev

How do you detect a SwiftUI touchDown event with no movement or duration?

分類Dev

How do you detect a SwiftUI touchDown event with no movement or duration?

分類Dev

Get duration of video with AVFoundation

分類Dev

where is mouse cursor movement acceleration and scroll wheel acceleration implemented in MacOSX

分類Dev

How to start mouse movement action triggering script after countdown?

分類Dev

MySQL Get duration between gaps

分類Dev

How to get sound duration in AppInventor?

分類Dev

MySQL get time duration up to a selected action

分類Dev

Get total duration of video files in a directory

分類Dev

Move an object on x axis like the movement of the mouse position (Unity3d)

分類Dev

Java Game (arrow-controlled) is slowed, except during mouse movement outside JFrame

分類Dev

SwiftUI: How to get continuous updates from Slider

分類Dev

SwiftUI: How to get continuous updates from Slider

分類Dev

Get continuous scroll events in iOS Chrome

分類Dev

Trying to get a triangle to point to the mouse

分類Dev

Can one get a mouse for the console?

分類Dev

duration().get(String) と duration().as(String) の違いは何ですか?

分類Dev

How can I get the remaining duration of an SCNAction currently in progress?

分類Dev

How do you get the duration of a .gif file in c#?

分類Dev

How to get cycling duration from HealthKit for ios app using Swift

分類Dev

Mouse Events get Ignored on the Underlying Layer

分類Dev

How to get an "mouse over" event in kivy

分類Dev

Change mouse pointer on click and get back on release

分類Dev

get text of element id using mouse click

分類Dev

Elm How to make custom event decoder to get mouse x/y position at mouse-wheel-move

分類Dev

How to get the mouse coordinates stored in a variable in open layers?

分類Dev

How to get the widget in QLayout under the mouse by Drag&drop?

Related 関連記事

  1. 1

    Smooth mouse movement in C++

  2. 2

    UWP + DirectX11: Mouse movement

  3. 3

    How do you detect a SwiftUI touchDown event with no movement or duration?

  4. 4

    How do you detect a SwiftUI touchDown event with no movement or duration?

  5. 5

    Get duration of video with AVFoundation

  6. 6

    where is mouse cursor movement acceleration and scroll wheel acceleration implemented in MacOSX

  7. 7

    How to start mouse movement action triggering script after countdown?

  8. 8

    MySQL Get duration between gaps

  9. 9

    How to get sound duration in AppInventor?

  10. 10

    MySQL get time duration up to a selected action

  11. 11

    Get total duration of video files in a directory

  12. 12

    Move an object on x axis like the movement of the mouse position (Unity3d)

  13. 13

    Java Game (arrow-controlled) is slowed, except during mouse movement outside JFrame

  14. 14

    SwiftUI: How to get continuous updates from Slider

  15. 15

    SwiftUI: How to get continuous updates from Slider

  16. 16

    Get continuous scroll events in iOS Chrome

  17. 17

    Trying to get a triangle to point to the mouse

  18. 18

    Can one get a mouse for the console?

  19. 19

    duration().get(String) と duration().as(String) の違いは何ですか?

  20. 20

    How can I get the remaining duration of an SCNAction currently in progress?

  21. 21

    How do you get the duration of a .gif file in c#?

  22. 22

    How to get cycling duration from HealthKit for ios app using Swift

  23. 23

    Mouse Events get Ignored on the Underlying Layer

  24. 24

    How to get an "mouse over" event in kivy

  25. 25

    Change mouse pointer on click and get back on release

  26. 26

    get text of element id using mouse click

  27. 27

    Elm How to make custom event decoder to get mouse x/y position at mouse-wheel-move

  28. 28

    How to get the mouse coordinates stored in a variable in open layers?

  29. 29

    How to get the widget in QLayout under the mouse by Drag&drop?

ホットタグ

アーカイブ