實(shí)現(xiàn)從當(dāng)前頁(yè)面左滑跳轉(zhuǎn)到當(dāng)前頁(yè)面或其他頁(yè)面
<view class="container" bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd">
let isNavigateed = false, // 是否已經(jīng)跳轉(zhuǎn)過(guò) *跳轉(zhuǎn)到當(dāng)前頁(yè)面需要
isTouchMove = false // 手勢(shì)是否為滑動(dòng) *這個(gè)字段必須 解決用戶使用點(diǎn)擊進(jìn)行跳轉(zhuǎn)bug
data: {
touchS: [0, 0],
touchE: [0, 0],
screenWidth: wx.getSystemInfoSync().screenWidth // 獲取當(dāng)前設(shè)備的寬度
}晚岭,
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
*/
onShow: function () {
isNavigateed = isTouchMove = false // 如果是跳轉(zhuǎn)到當(dāng)前頁(yè)面需要重置數(shù)據(jù)
},
// 記錄起始位置
touchStart: function (e) {
let sx = e.touches[0].pageX
let sy = e.touches[0].pageY
this.data.touchS = [sx, sy]
},
// 移動(dòng)
touchMove: function (e) {
isTouchMove = true
let sx = e.touches[0].pageX
let sy = e.touches[0].pageY
this.data.touchE = [sx, sy]
},
// 結(jié)束位置
touchEnd: function (e) {
let start = this.data.touchS
let end = this.data.touchE
// this.data.screenWidth - start[0] < 10 意義為用戶盡量為從設(shè)備最右側(cè)開(kāi)始滑動(dòng)
if (start[0] > end[0] + 100 && !isNavigateed && isTouchMove && this.data.screenWidth - start[0] < 10) {
isNavigateed = true;
wx.navigateTo({
url: '/pages/photograph/photograph',
})
}
},
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者