<view @longpress="longpressBtn()" @touchend="touchendBtn()">
<view class="dade_start" @touchstart="start" @touchend="end" @touchmove="move">长按录音</view>
</view>
// 触摸touch事件
start(e){ //@touchstart 触摸开始
this.transition = '.1s';
this.startData.clientX = e.changedTouches[0].clientX; //手指按下时的X坐标
this.startData.clientY = e.changedTouches[0].clientY; //手指按下时的Y坐标
},
end(e){ //@touchend触摸结束
this.moveX = 0; //触摸事件结束恢复原状
this.transition = '.5s';
if(Math.abs(this.touch.clientX-this.startData.clientX) > 100) { //在事件结束时,判断滑动的距离是否达到出发需要执行事件的要求
console.log('执行查看跳转事件');
// this.touch = {};
} else {
console.log('滑动距离不够,不执行跳转')
// this.touch = {};
}
},
move(event) { //@touchmove触摸移动
let touch = event.touches[0]; //滑动过程中,手指滑动的坐标信息 返回的是Objcet对象
// console.log(touch);
this.touch = touch;
let data = touch.clientY - this.startData.clientY;
if(touch.clientY < this.startData.clientY) { //向上移动
if(data<-50) {
data = -50;
}
console.log('上')
}
if(touch.clientY > this.startData.clientY) { //向下移动
if(this.moveY == 0) {
data = 0
} else {
if(data>50) {
data = 50;
}
}
console.log('下')
}
this.moveY = data;
console.log(data);
},