移动端屏幕长按事件

608 阅读1分钟

html页面

<div class="invite_code"
  @touchstart="touchStart"
  @touchend="touchEnd"
  @touchmove="gotouchMove">
</div>

js逻辑

 /** 触屏开始 */
    touchStart() {
      clearTimeout(this.timeOutEvent); //清除定时器
      this.timeOutEvent = 0;
      this.timeOutEvent = setTimeout(() => {
      	//长按行为的操作函数
        this.longPress();
      }, 1500); //这里设置定时
    },
    /** 触屏结束 */
    touchEnd() {
      clearTimeout(this.timeOutEvent);
      if (this.timeOutEvent != 0) {
      }
    },
    /**定时器清楚 */
    gotouchMove() {
      clearTimeout(this.timeOutEvent); //清除定时器
      this.timeOutEvent = 0;
    }