
WXML:
<view class='btn' bindtouchstart='touchStart' bindtouchmove='touchMove' bindtouchend='touchEnd'>
OK
</view>
JS:
data: {
touchS : [0,0],
touchE : [0,0]
},
touchStart: function(e){
// console.log(e.touches[0].pageX)
let sx = e.touches[0].pageX
let sy = e.touches[0].pageY
this.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.touchS
let 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('静止')
}
},
在 touchstart 时,监听到触摸开始时的 (x, y)位置;在 touchMove 方法中持续监听触摸点的位置(x, y),并保存在 data 中;在 touchEnd 方法中对开始的触摸位置和结束的触摸位置进行判断,如果移动距离大于 50 则判定为发生触摸滑动事件。
在上面示例中,当 X 轴方向的移动超过 50 时即判定为左滑或右滑,相应的也可以通过判断 Y 轴方向的滑动长度,来判断上滑或是下滑,由此实现触摸滑动的功能。
更多信息联系我的微
打开的url列表,作为历史记录信息,当用户点击枝搏返回时捕获返回按钮事件,历史记录信息不为空,执行loadUrl到上一个界面猛竖祥,同时把历史记录信息去除一条。
小程序是指微信公众平台小程序,小程序可以帮助开发者快速的开发小程序,小程序可以在微信内被便捷地获取和传播;是一种不需要下载安装即可使用的应用小程序,和原有的三种公众号是并行的体系。
微信小程序的能力,包括线下扫码、对话分享、纤带消息通知、小程序切换、历史列表、公众号关联和搜索查找等7大功能。
小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用。也体现了“用完即走”的理念,用户不用关心是否安装太多应用的问题。应用将无处不在,随时可用,但又无需安装卸载。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)