微信小程序长按与点击事件冲突解决方案

问题再现

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

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

解决方案

abc.wxml

<view bindtouchstart="bindTouchStart" bindtouchend="bindTouchEnd" bindlongtap="bingLongTap" bindtap="bindTap">view>

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


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部