<view @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" ></view>
touchStart(e){
let { clientX, clientY } = e.touches[0]
this.startX = clientX
this.tapStartX = clientX
this.tapStartY = clientY
this.tapStartTime = e.timeStamp
this.$apply()
},
// 触摸结束事件
touchEnd(e){
let { clientX, clientY } = e.changedTouches[0]
let endTime = e.timeStamp
// 快速滑动
if (endTime - this.tapStartTime <= 300) {
// 向左
if (Math.abs(this.tapStartY - clientY) < 50) {
console.log();
if (this.tapStartX - clientX > 5) {
// 向左滑,执行事件
} else if (this.tapStartX - clientX < -5){
// 向右滑,执行事件
}
}
}
this.$apply()
},
touchMove(e){
let { clientX } = e.touches[0]
let offsetX = this.startX - clientX
this.startX = clientX
this.$apply()
},
手指在屏幕上左右滑动(滑动切换tab 等)
最新推荐文章于 2024-07-22 01:47:16 发布