0
我发现了一个解决方案,用于在Detecting if the user is idle with JavaScript and YUI 3上检测浏览器上用户的空闲状态。如何在jQuery中使用webkit的浏览器上检测到空闲状态
它在FireFox上运行良好,但有时它并不在Chrome,Safari中。这些浏览器始终调用mousemove事件。
任何人有其他的解决方案呢?
我发现了一个解决方案,用于在Detecting if the user is idle with JavaScript and YUI 3上检测浏览器上用户的空闲状态。如何在jQuery中使用webkit的浏览器上检测到空闲状态
它在FireFox上运行良好,但有时它并不在Chrome,Safari中。这些浏览器始终调用mousemove事件。
任何人有其他的解决方案呢?
我现在已经找到了解决方案。在空闲timer.js,我更新了它作为跟随 1 /搜索跟踪代码
var idle = false, //indicates if the user is idle
tId = -1, //timeout ID
enabled = false, //indicates if the idle timer is enabled
timeout = 30000; //the amount of time (ms) before the user is considered idle
,并在接下来的上述
prevMousePos = { x: -1, y: -1 };
currentMousePos = { x: -1, y: -1 };
如果你的代码没有工作添加两个以下行,你可以尝试event.screenX,event.screenY。
2 /替换这一行
clearTimeout(tId);
与
if(e.type == 'mousemove'){
currentMousePos.x = event.pageX;
currentMousePos.y = event.pageY;
if(currentMousePos == prevMousePos){
enabled = false;
}
else{
prevMousePos = currentMousePos;
clearTimeout(tId);
}
}
else if(e.type == 'mousemove'){
clearTimeout(tId);
}
else if(e.type == 'keydown'){
clearTimeout(tId);
}