微信小程序监听手势滑动切换页面的示例

  介绍

这篇文章主要介绍了微信小程序监听手势滑动切换页面的示例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。

<强>微信小程序监听手势滑动切换页面

<强> 1。对应的xml里写上手势开始,滑动,结束的监听:

& lt; view 类=皌ouch", bindtouchstart=皌ouchStart", bindtouchmove=皌ouchMove", bindtouchend=皌ouchEnd",祝辞& lt;/view>

<强> 2。js:

var  touchDot =, 0;//触摸时的原点,   var  time =, 0;//,时间记录,用于滑动时且时间小于1 s则执行左右滑动,   var  interval =,““//,记录/清理时间记录,   页面({,   ,数据:{…},   ,,}) 页面({,   数据:,{大敌;   ,,,,,,   },大敌;   ,//触摸开始事件,   ,touchStart: function  (e), {,   时间=touchDot 才能;e.touches [0] .pageX;,//,获取触摸时的原点,//,才能使用js计时器记录时间,,   时间=interval 才能;setInterval (function  (), {,   ,,时间+ +,,   ,,},100);,   },大敌;   ,//触摸移动事件,   ,touchMove: function  (e), {,   var 才能;touchMove =, e.touches [0] .pageX;,   console.log才能(“touchMove:“, +, touchMove  +,“, touchDot:“, +, touchDot  +,“, diff:“, +, (touchMove 作用;touchDot)),,//,才能向左滑动,,   if 才能;(touchMove 作用;touchDot  & lt;=, -40,,,, time  & lt;, 10), {,   ,,wx.switchTab ({,   ,,,url:, & # 39; . ./左滑页面/左滑页面& # 39;,   ,,});,,   ,,},//,才能向右滑动,   if 才能;(touchMove 作用;touchDot 祝辞=,40岁,,,,time  & lt;, 10), {,   ,,console.log(& # 39;向右滑动& # 39;),,   ,,wx.switchTab ({,   ,,,url:, & # 39; . ./右滑页面/右滑页面& # 39;,   ,,});,,   ,,},   },大敌;   ,//触摸结束事件,   ,touchEnd: function  (e), {,   clearInterval才能(间隔);,//,清除setInterval    time 才能=,0,,   },大敌;   又是;   又是;   又是;   })

感谢你能够认真阅读完这篇文章,希望小编分享的“微信小程序监听手势滑动切换页面的示例”这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!

微信小程序监听手势滑动切换页面的示例