const waitOperate = (callback, second) => { let count = 0; let x; let y; let timer; //监听鼠标 document.onmousemove = function (event) { const x1 = event.clientX; const y1 = event.clientY; if (x != x1 || y != y1) { count = 0; } x = x1; y = y1; }; //监听键盘 document.onkeydown = function () { count = 0; }; function countTime() { count++; if(count >= second){ callback(); count = 0; // clearInterval(timer); } } timer = setInterval(countTime, 1000) ; }