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 >
新手求喷~