我一直在研究并发现在用户空闲x个时间后检测不活动的代码(当用户没有触摸屏幕时),这在使用鼠标时工作得很好,但当我尝试在触摸屏设备上使用它时,它无法检测到我的手指或工作。我已经添加了很多DOM事件,比如"touchstart“、"touchmove”、"touchend“、"touchcancel”等等,但它们似乎也不起作用。以下是我的代码
var idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 3000);
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 1) {
alert("ok");
}
}
https://stackoverflow.com/questions/52649058
复制相似问题