H5 移动端长按

1,306 阅读1分钟

js代码

 touchStart = parameter => {               // 触摸开始
        this.timeOutEvent = setTimeout(() => {
              this.function(parameter)       // 长按触发的方法
        }, 500)
  }
  touchEnd = () => {    // 触摸结束
        clearTimeout(this.timeOutEvent)  // clearTimeout() 方法可取消由 setTimeout() 方法设置的定时操作。
        return false
  }
  touchMove = () => {            // 触摸移动被中断
        clearTimeout(this.timeOutEvent)
        this.timeOutEvent = 0
  }

html部分

<div 
onTouchStart={() => this.touchStart(参数)} 
onTouchEnd={this.touchEnd} 
onTouchMove={this.touchMove}
>
    长按我
</div>

参考出处及其他相关的文章

blog.csdn.net/u011588551/… blog.csdn.net/weixin_4368…