87,993
社区成员
发帖
与我相关
我的任务
分享
var initSleep = 30;
window.onload = function(){
this.sleep = initSleep;
document.onmousemove = document.onmousedown = document.onkeydown = function(e){window.sleep = initSleep}
setInterval(function(){this.sleep === 0 ? toDo() : this.sleep --},1000)
}
function toDo(){
console.log(this.sleep);
this.sleep = initSleep;//修改这个时间就好了啊
}
var timer;
document.onmousedown = document.onkeydown = function () {
clearTimeout(timer);
timer = setTimeout(function(){
alert("30秒无操作");
}, 100000);
}
var tick=0;
window.onload = function () {
setInterval(function () {
tick++;
if (tick > 30) {
//超过30s
}
}, 1000);
}
document.onmousemove = document.onkeydown = function () { tick = 0 };
能改成对页面操作结束后1分钟无操作,再执行方法吗?(不好意思,我之前没说清楚)
var initSleep = 2;
window.onload = function(){
this.sleep = initSleep;
document.onmousemove = document.onmousedown = document.onkeydown = function(e){window.sleep = initSleep}
setInterval(function(){this.sleep === 0 ? toDo() : this.sleep --},1000)
}
function toDo(){
console.log(this.sleep);
this.sleep = initSleep;
}
var timer;
window.onload = document.onmousemove = document.onkeydown = function () {
clearTimeout(timer);
timer = setTimeout(function(){
alert("30秒无操作");
}, 30000);
}