微信滑动跳转涉及到三个函数:
1.bindtouchstart 点击时触发
2.bindtouchmove 鼠标点击后移动时触发
3.bindtouchend 鼠标点击停止后触发
原理:通过比对pageX的值来判断左移右移
一.首先在wxml中定义好触发函数的事件名
<view class="navto" bindtap="navto" bindtouchstart="touchstar" bindtouchmove="touchmove" bindtouchend="touchend"></view>
二.处理定义函数值,与判断
var beginx = 0;
var endx = 0;
touchstar:function(e){
beginx = e.touches[0].pageX;
},
touchmove:function(e){
endx = e.touches[0].pageX;
},
touchend:function(e){
if(beginx>endx){
console.log("右滑")
}else{
console.log("左滑")
}
}
三.关于微信小程序的栈值,微信小程序栈值最多为10,建议左滑的时候返回上一页,通过
wx.navigateBack({
delta: 1 //返回上一个页面
})
返回上一页减少栈值。