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);
}