为window添加mousemove,移动时设置变量为true,静止后为false; (function(){ let isMove = false, timer = null; window.onmousemove = function(){ isMove = true; clearTimeout(timer); console.log(isMove); // 移动时 timer = setTimeout(function(){ isMove = false; console.log(isMove); // 静止后 },200); } }());
为window添加mousemove,移动时设置变量为true,静止后为false;