when Mini Program bindtouchend slides to the left, moving out of the screen does not trigger it, but moving up and down to the right can trigger
wxml
<view id="id" class = "ball" bindtouchstart = "handletouchtart" bindtouchmove="handletouchmove" bindtouchend="handletouchend" style = "width : 100%px; height : 40px;">
{{text}}
</view>
wxss
.ball {
box-shadow:2px 2px 10px -sharpAAA;
border-radius: 20px;
position: absolute;
left: 50%;
top: 50%;
}
js
Page({
data: {
lastX: 0, //x
lastY: 0, //y
text: "",
currentGesture: 0, //
},
//
handletouchmove: function (event) {
var currentX = event.touches[0].pageX
var currentY = event.touches[0].pageY
var tx = currentX - this.data.lastX
var ty = currentY - this.data.lastY
var text = ""
//
if (Math.abs(tx) > Math.abs(ty)) {
if (tx < 0)
text = ""
else if (tx > 0)
text = ""
}
//
else {
if (ty < 0)
text = ""
else if (ty > 0)
text = ""
}
//
this.data.lastX = currentX
this.data.lastY = currentY
this.setData({
text: text,
});
},
//
handletouchtart: function (event) {
//console.log(this.data.lastX)
this.data.lastX = event.touches[0].pageX
this.data.lastY = event.touches[0].pageY
},
//
handletouchend: function (event) {
console.log(event)
this.data.currentGesture = 0;
this.setData({
text: "",
});
},
})