微信小程序监控手势滑动切换页面实例详解
微信小程序监控手势滑动切换页面实例详解1。在相应的XML中,对手势的开始、滑动和结束进行监视。
2.js:
无功touchdot = 0; / /触摸的起源
var时间= 0;在执行时间附近滑动和滑动的时间记录小于1s。
var
页({
数据:{…}
})
页({
数据:{
…
},
启动/触摸事件
TouchStart:功能(e){
touchdot = e.touches { 0 }。pagex; / /得到触摸的起源
使用js定时器记录时间
区间= setInterval(){()函数(
时间+;
},100);
},
触摸/移动事件
touchmove:功能(e){
VaR touchmove = e.touches { 0 }。pagex;
console.log(touchmove:+ +touchdot touchmove:+ touchdot +diff:+(touchmove - touchdot));
向左滑动
如果(touchmove - touchdot - 40次<< = 10){
Wx.switchTab({
URL:左/左页/左页
});
}
幻灯片
如果(touchmove - touchdot,时间< 10 > = 40){
console.log('sliding右边的);
Wx.switchTab({
URL:…..右幻灯片页/右幻灯片页
});
}
},
触摸/结束事件
TouchEnd:功能(e){
ClearInterval(间隔); / /清除setInterval
时间= 0;
},
。
。
。
})
谢谢你的阅读。我希望你能帮助你,谢谢你对这个站的支持。