【发布时间】:2019-03-09 23:36:44
【问题描述】:
我一直在研究并发现在用户闲置 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");
}
}
【问题讨论】:
-
定义“不活动”。我是不是盯着你的页面看了一会儿又重新阅读,而没有移动鼠标“不活动”?
-
是的,对于一个含糊的问题很抱歉
标签: javascript jquery