首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用javascript检测触摸设备上的非活动状态

使用javascript检测触摸设备上的非活动状态
EN

Stack Overflow用户
提问于 2018-10-04 22:19:46
回答 2查看 2K关注 0票数 1

我一直在研究并发现在用户空闲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");
      }
    }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52649058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档