微信小程序的双击事件

版权声明:如需转发,与我联系 https://blog.csdn.net/qq_41473887/article/details/79959232

index.js

Page ({
data : {
starTime : 0 ,
ClickNum : 0 ,
show : false
},
//点击事件
myClick : function (e ) {
var that = this
var curTime = e .timeStamp ;
var starTime = this .data .starTime ;
if (that .data .starTime === 0 ) {
this .setData ({
starTime : curTime
})
setTimeout ( function () {
that .resetClick ();
if (that .data .ClickNum === 1 ) {
// 双击执行事件区
that .setData ({
starTime : 0 ,
ClickNum : 0 ,
show :!that .data .show
})
}
}, 300 )
// 300为双击的时间间隔
} else {
if (curTime - starTime < 300 ) {
this .setData ({
ClickNum : 1
})
}
}
},
// 单击重置
resetClick : function () {
if ( this .data .ClickNum === 0 ) {
this .setData ({
starTime : 0 ,
ClickNum : 0
})
}
}

})


indx.wxml

< view >
< button type = "primary" bindtap = "myClick" > 双击事件 </ button >

< view wx:if= "{{show}}" >
双击事件
</ view >
</ view >


新手求喷~

猜你喜欢

转载自blog.csdn.net/qq_41473887/article/details/79959232