For the same controls and set bindtap and bindlongtap, you will find a long time bindlongtap event occurs first, and then trigger a click event.
Applet execution sequence of events is
Click: touchstart → touchend → tap
Press touchstart → longtap → touchend → tap
To resolve this conflict, in the absence of choice of action, will depart tap event:
- Defines a face longtap = 0
- In longtap event, the assignment longtap = 1
- In the tap event, if the value longtap is 0, the normal processing
- In the tap event, if the value longtap is 1, then the assignment longtap = 2
- In the tap event, if the value longtap is 2, then the assignment longtap = 0
Code
wxml
bindlongtap="chunkLongTap" bindtap="gotoChunk"
js
let longTap = 0 // 0 not
// 1 long tap
// 2 tap (follows the long tap in a same action)
chunkLongTap (ev)
{
longTap = 1
},
gotoChunk (ev)
{
const ckid = ev.currentTarget.dataset.ckid
if (ckid && this.data.theChapter.switch === 'on') {
if (longTap === 0) {
wx.navigateTo({
url: `/pages/book_chunk/chunk?ckid=${ckid}`,
})
}
else if (longTap === 1) {
longTap = 2
}
else if (longTap === 2) {
longTap = 0
}
}
},