<template>
<view class="pages" @touchstart="touchStart" @touchend="touchEnd">
<view class="title">
<view class="e_title" v-for="(item,index) in list1" :key="index"
@click.stop="e_click(index)">
<view :class="num === index ? 'title_fw_big' : 'title_color'">{{item}}</view>
</view>
</view>
<view class="content" v-if="num == 0">内容1</view>
<view class="content" v-if="num == 1">内容2</view>
<view class="content" v-if="num == 2">内容3</view>
</view>
</template>
<script>
export default {
data() {
return {
list1: ['标签1', '标签2', '标签3'],
num: 0,
touchStartX: 0,
touchStartY: 0,
};
},
methods: {
e_click(index) {
this.num = index;
},
touchStart(e) {
this.touchStartX = e.touches[0].clientX;
this.touchStartY = e.touches[0].clientY;
},
touchEnd(e) {
let deltaX = e.changedTouches[0].clientX - this.touchStartX;
let deltaY = e.changedTouches[0].clientY - this.touchStartY;
console.log(deltaX,deltaY,Math.abs(deltaX),Math.abs(deltaY));
console.log('kkkk',deltaX );
if (Math.abs(deltaX) > 50 && Math.abs(deltaX) > Math.abs(deltaY)) {
if (deltaX >= 0) {
console.log("右滑")
if(this.num == 0 ){
this.num = 0
}else if(this.num == 1 ){
this.num = 0
}else if(this.num == 2 ){
this.num = 1
}
} else {
console.log("左滑")
if(this.num == 0 ){
this.num = 1
}else if(this.num == 1 ){
this.num = 2
}else if(this.num == 2 ){
this.num = 2
}
}
}
else {
console.log("可能是点击!")
}
},
}
};
</script>
<style scoped>
.pages{
width: 100%;
height: 100vh;
background-color: #F0F0F0;
}
.title {
display: flex;
justify-content: space-around;
align-items: center;
height: 80rpx;
background: #B3D66E;
position: fixed;
left: 0;
top: 0;
width: 100%;
box-sizing: border-box;
}
.e_title {
display: flex;
align-items: center;
flex-direction: column;
padding: 15rpx 20rpx;
font-weight: 300;
}
.title_color {
font-size: 24rpx;
color: #969696;
}
.title_fw_big {
font-size: 30rpx;
font-weight: bold;
color: #191919;
border-bottom: 8rpx solid #F0AD4E;
}
.content{
margin-top: 80rpx;
width: 100%;
height: calc(100vh - 80rpx);
background-color: #FE726B;
text-align: center;
font-size: 100rpx
}
</style>