当我们在一个标签上同时设置bindtap和bindlongtap时, 会发现长按时先出现bindlongtap的事件,然后紧接着也会触发点击事件。
显然,大部分时候,这并不是我们想要的事件执行结果。
我们知道,微信小程序中事件执行的顺序是
点击:touchstart → touchend → tap
长按 touchstart → longtap → touchend → tap

解决方法:
通过点击事件来判定是点击还是长按。

bindTouchStart: function(e) {
    this.startTime = e.timeStamp;
},
bindTouchEnd: function(e) {
    this.endTime = e.timeStamp;
},
bindTap: function(e) {
    if(this.endTime  - this.startTime < 350) {
        console.log("点击")
    }
},
bingLongTap: function(e) {
    console.log("长按");
}

相关文章:

  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
猜你喜欢
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案