簡體   English   中英

jQuery-記錄鼠標懸停和鼠標休息的時間?

[英]JQuery - Recording time on mouse hover and on mouse rest?

我想記錄兩個不同的JavaScript事件的時間。 一個用於鼠標不動時,另一個用於鼠標不動時。

$(document).ready(function() {
  var timeStart = new Date().getTime();
  var elapsedTime = (timeEnd - timeStart)/1000
});

我知道JQuery事件mousemove但是不知道如何在鼠標移動時跟蹤時間

嘗試這個:

$(document).ready(function () {
  var timer = null;
  var idleTime = 0;
  timer = setInterval(timerIncrement, 1000);
  $(document).bind("mousemove", function (e) {
     idleTime = 0;
  });

  function timerIncrement() {
   idleTime = idleTime + 1;     
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM