在 mousemove 或 scroll 我想重置一个计时器,如果它没有运行并且在计时器函数内部运行一个函数一次。到目前为止,我有这个...
var timerId,
lastActive = new Date().getTime(),
token;
var timerFunc = function () {
var currentTime = new Date().getTime();
var timeDiff = currentTime - lastActive;
if (timeDiff > 10000) {
//clearInterval(timerId);
}
//I want to do some logic here
// but only on the first iteration of the timer
//how can I do that?
};
$(window).on('mousemove scroll', function (e) {
lastActive = new Date().getTime();
//only restart the timer if its not currently running. How can I do that??
if(resetTimer)
timerId = setInterval(timerFunc , 10000);
});
timerId = setInterval(timerFunc , 10000);
任何 javascript 大师可以帮助我填写这些内容吗?如果我太简短了,我很抱歉。我会在评论中跟进任何问题。谢谢大家的任何提示、链接、技巧等。干杯。=)