<template>
<div id="app" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
<keep-alive include="Home">
<router-view />
</keep-alive>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
startMoveX: 0,
startMoveY: 0,
moveEndX: 0,
moveEndY: 0,
}
},
methods: {
touchStart(e) {
// e.preventDefault();
this.startX = e.changedTouches[0].pageX;
this.startY = e.changedTouches[0].pageY;
},
touchMove(e) {
// e.preventDefault();
this.moveEndX = e.changedTouches[0].pageX;
this.moveEndY = e.changedTouches[0].pageY;
let X = this.moveEndX - this.startX;
let Y = this.moveEndY - this.startY;
if (Math.abs(X) > Math.abs(Y) && X > 0) {
console.log("left 2 right");
} else if (Math.abs(X) > Math.abs(Y) && X < 0) {
console.log("right 2 left");
} else if (Math.abs(Y) > Math.abs(X) && Y > 0) {
console.log("top 2 bottom");
} else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
console.log("bottom 2 top");
} else {
console.log("just touch");
}
},
touchEnd(e) {},
}
}
</script>
<style></style>
vue监听页面滑动方向
最新推荐文章于 2023-08-10 16:55:08 发布