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

前端 未结 5 752
一生所求
一生所求 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:23

    Although it is not jQuery but I've done it this way in my Android app:

    1. registered events listeners:

      var touchStartTimeStamp = 0;
      var touchEndTimeStamp   = 0;
      
      window.addEventListener('touchstart', onTouchStart,false);
      window.addEventListener('touchend', onTouchEnd,false);
      
    2. added functions:

      var timer;
      function onTouchStart(e) {
          touchStartTimeStamp = e.timeStamp;
      }
      
      function onTouchEnd(e) {
          touchEndTimeStamp = e.timeStamp;
      
          console.log(touchEndTimeStamp - touchStartTimeStamp);// in miliseconds
      }
      
    3. checked time difference and did my stuff

    I hope this will help.

提交回复
热议问题