100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 微信小程序监听手势左右滑动

微信小程序监听手势左右滑动

时间:2022-11-16 06:52:48

相关推荐

微信小程序监听手势左右滑动

1.在view标签绑定上touchStart,touchMove,touchEnd事件

<view bindtouchstart='touchStart' bindtouchmove='touchMove' bindtouchend="touchEnd">监听左右滑动事件</view>

2.在js中写上

Page({/*** 页面的初始数据*/data: {touchS : [0,0],touchE : [0,0]},// 触摸开始事件touchStart: function(e){// console.log(e.touches[0].pageX)let sx = e.touches[0].pageXlet sy = e.touches[0].pageYthis.data.touchS = [sx,sy]},// 触摸滑动事件touchMove: function(e){let sx = e.touches[0].pageX;let sy = e.touches[0].pageY;this.data.touchE = [sx, sy]},// 触摸结束事件touchEnd: function(e){let start = this.data.touchSlet end = this.data.touchE// console.log(start)// console.log(end)if(start[0] < end[0] - 50){// console.log('向右滑,这里可以调用方法,及页面跳转事件')}else if(start[0] > end[0] + 50){// console.log('向左滑,这里可以调用方法,及页面跳转事件')}else{// console.log('向上或向下滑动')}},})

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。