需求:
頁面長時(shí)間未操作時(shí),彈窗提示
持續(xù)有交互則不提示
該代碼比較簡單沒有做封裝停局,可以根據(jù)自己需求進(jìn)行封裝
function actionListener(){
var count = 0;
var outTime = 2; //分鐘
function go() {
count++;
if (count == outTime * 60 ) {
// alert('您長時(shí)間未操作頁面');
// 此處處理后續(xù)操作
}
}
//頁面倒計(jì)時(shí)
window.setInterval(go, 1000);
//監(jiān)聽鼠標(biāo)
var x;
var y;
document.onmousemove = function(event) {
/* Act on the event */
var x1 = event.clientX;
var y1 = event.clientY;
if (x != x1 || y != y1) {
count = 0;
}
x = x1;
y = y1;
};
document.onkeydown = function(event) {
count = 0;
};
}