洛枫学院

洛枫学院 » HTML/HTML5 » vue中如何用js的touchstart+touchend实现长按事件

页码: 1

vue中如何用js的touchstart+touchend实现长按事件

- 一片云 2021-09-27 11:36

touchstart:接触了屏幕,延时500毫秒执行;
touchend:离开了屏幕,离开的时候清理延时事件;

代码 复制 - 运行

// 长按事件
    touchstart(){
     this.timeOutEvent = setTimeout(function() {
      console.log("长按事件触发");
     }, 500);
    },
    touchend(){
     clearTimeout(this.timeOutEvent);
    },

页码: 1