1. 程式人生 > >滑動事件 左滑 右滑

滑動事件 左滑 右滑

// 滑動開始事件

handletouchtart(e) {

this.data.lastX = e.touches[0].pageX;

this.data.lastY = e.touches[0].pageY;

},

handletouchend(event) {

const touchMoveX = event.changedTouches[0].pageX;

const touchMoveY = event.changedTouches[0].pageY;

const tmX = touchMoveX - this.data.lastX;

const tmY = touchMoveY - this.data.lastY;

const absX = Math.abs(tmX);

const absY = Math.abs(tmY);

if (absX > 2 * absY) {

if (tmX < 0) {

console.info('向左滑動');

} else {

console.log('右滑=====');

}

}

if (absY > absX * 2 && tmY < 0) {

console.log('上滑動=====');

}

},