Determining Long Tap (Long Press, Tap Hold) on Android with jQuery

前端 未结 5 753
一生所求
一生所求 2021-01-02 10:30

I\'ve been able to successfully play with the touchstart, touchmove, and touchend events on Android using jQuery and an HTML page. Now I\'m trying to see what the trick is t

5条回答
  •  我在风中等你
    2021-01-02 11:09

    I did something like this:

    var touchCounter;
    
    window.addEventListener('touchstart', function () {
      var count = 0;
      touchCounter = setInterval(function () {
        count++;
        if (count == 10) alert('touch lasted 10 seconds');
      }, 1000);
    });
    
    window.addEventListener('touchend', function () {
      clearInterval(touchCounter);
      touchCounter = null;
    });
    

提交回复
热议问题