上下左右滑动的时候,不识别if语句里面的程序
来自课程:微信小程序-贪吃蛇
Page({
/**
* 页面的初始数据
*/
data: {
score:0,
maxScore:100,
startx:0,//触摸开始的横纵坐标
starty:0,
endx:0,
endy:0,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
tabStart:function(e){
console.log("开始点击"),
console.log(e),
this.setData({
startx:e.touches[0].PageX,
starty:e.touches[0].PageY
})
},
tabMove:function(e){
console.log("开始移动")
this.setData({
endx:e.touches[0].PageX,
endy:e.touches[0].PageY
})
},
tabEnd:function(){
var heng = this.data.endx?(this.data.endx - this.data.startx):0
var zong = this.data.endy?(this.data.endy - this.data.starty):0
console.log(heng)
if (heng > zong && heng > 0){
console.log("向右滑动")
}
else if (Math.abs(heng) > Math.abs(zong) && heng<0) {
console.log("向左滑动")
}
else if (Math.abs(zong) > Math.abs(heng) && zong>0) {
console.log("向下滑动")
}
else if (Math.abs(zong) > Math.abs(heng) && zong<0) {
console.log("向上滑动")
}else{
console.log(" 点击未滑动")
}
}
})
startx:e.touches[0].PageX,
starty:e.touches[0].PageY马大哈,,
startx:e.touches[0].pageX,
starty:e.touches[0].pageY
应该小写

