微信小程序--长按事件bindlongtap与点击事件bindtap的执行顺序

对于同一控件同时设置bindtap和bindlongtap,会发现长按时先出现bindlongtap的事件,然后触发点击事件。

通过测试,我们发现,小程序中事件执行的顺序是 
点击:touchstart → touchend → tap 

长按 touchstart → longtap → touchend → tap

<view bindtouchstart="bindTouchStart" bindtouchend="bindTouchEnd" bindlongtap="bingLongTap" bindtap="bindTap">蹂躏我</view>

// js

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("长按");

}

猜你喜欢

转载自blog.csdn.net/aaron9185/article/details/80461409
今日推荐