//js
......
let timer = null;
Page({
data: {
startTime: 0,
clickNum: 0
},
doubleClick: function(e) {
let that = this;
let curTime = e.timeStamp;
let startTime = this.data.startTime;
if(startTime == 0){
that.setData({
startTime: curTime
})
timer = setTimeout(function(){
that.resetClick();
if(that.data.clickNum == 1){
console.log("双击执行事件");
that.setData({
startTime: 0,
clickNum: 0
})
}else{
console.log("单击执行事件");
}
clearTimeout(timer);
},300);
}else{
if(curTime - startTime < 300){
this.setData({
clickNum: 1
})
}
}
},
resetClick: function(){
let that = this;
if (that.data.clickNum == 0) {
this.setData({
startTime: 0,
clickNum: 0
})
}
},
})
......
使用
//wxml
<view catchtap="doubleClick"></view>
网友评论