微信公众号+小程序
小程序手势滑动操作
发布时间:2017-10-12 17:33   来源:长沙网站制作   点击:次   字体:    
小程序手势滑动操作

touchmove: function (event) {
var that = this;
let currentX = event.touches[0].pageX
let currentY = event.touches[0].pageY
let tx = currentX - this.data.lastX
let ty = currentY - this.data.lastY
let text = ""
let currentGesture = ""
//左右方向滑动
if (Math.abs(tx) > Math.abs(ty)) {
if (tx < 0) {
text = "向左滑动"
currentGesture = 1
}
else if (tx > 0) {
text = "向右滑动"
currentGesture = 2
}

}
//上下方向滑动
else {
if (ty < 0) {
text = "向上滑动"
currentGesture = 3

}
else if (ty > 0) {
text = "向下滑动"
currentGesture = 4
}

}

//将当前坐标进行保存以进行下一次计算
this.data.lastX = currentX
this.data.lastY = currentY
this.setData({
currentGesture: currentGesture
});
},

touchstart: function (event) {
var that = this;
this.data.lastX = event.touches[0].pageX
this.data.lastY = event.touches[0].pageY
},

touchend: function(event){
var that = this;
var currentGesture = that.data.currentGesture;
if (currentGesture == "1"){
that.prevCon();
} else if (currentGesture == "2"){
that.nextCon();
} else if (currentGesture == "3"){
that.upCon();
} else if (currentGesture == "4"){
that.downCon();
}
},

关键字:小,程序,手势,操作,小,程序,手势,操作,touchmov

顶一下
(0)
0%
踩一下
(0)
0%
网站对话
web chat