<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/*
用户无操作时执行函数
noOperation(10, function(){
console.log("无操作10秒钟后执行");
})
*/
function noOperation (wait_time, callBack) {
var lastOperateTime = new Date();
var SCREENSAVER_TIME = wait_time * 1000;
function afterOperate() {
var thisOperateTime = lastOperateTime = new Date();
setTimeout(function () {
if (thisOperateTime === lastOperateTime) {
if (typeof callBack === "function") {
callBack()
} else {
console.log("未定义回调函数!")
}
} else { }
}, SCREENSAVER_TIME)
};
document.onmousedown = afterOperate;
document.onscroll = afterOperate;
document.onkeypress = afterOperate;
afterOperate()
}
</script>
</body>
</html>
用户在界面停留,无操作时执行的函数
最新推荐文章于 2024-08-12 09:24:46 发布