feat(cp排行榜): 历史榜首左右滑动切换效果实现

This commit is contained in:
hzj 2026-01-22 15:15:02 +08:00
parent 24b5354569
commit e9cb147436

View File

@ -42,13 +42,19 @@
style="width: 100%; height: 73%; min-width: 0; display: flex; overflow: hidden"
class="scrollX"
>
<div class="topList" :style="{ left: listLeftPosition }">
<div
class="topList"
:style="{ left: listLeftPosition }"
@touchstart="handleTouchStart"
@touchmove="handleTouchMove"
@touchend="handleTouchEnd"
>
<!-- 右占位 -->
<div style="width: 9vw; min-width: 0; flex-shrink: 0"></div>
<!-- top1情侣头像 -->
<itemCenter
v-for="(item, index) in 1"
v-for="(item, index) in seasonTop1List"
style="z-index: 1; min-width: 0; flex-shrink: 0; transition: all 0.8s ease"
:style="{ width: index === centerIndex ? '60vw' : '40vw' }"
:imgUrl="imageUrl('topCoupleFrame')"
@ -1403,28 +1409,66 @@ const myCouples = ref([]) // 伴侣列表
const selectedCouple = ref({}) //
const writeLetterText = ref('') //
const letterTextLength = ref(0) //
const seasonTop1List = ref([]) // Top1
const resultShowIndex = ref(0) //
const seasonTop1List = ref([{}]) // Top1
const listLeftPosition = ref('0') //top
const centerIndex = ref(0) // 1
//
const touchStartX = ref(0)
const touchEndX = ref(0)
//
const moveToCenter = (targetIndex) => {
if (centerIndex.value == targetIndex) return //
//
const itemWidth = 40 // vw
const itemSpacing = 2 // vw
//
const targetOffset = (itemWidth + itemSpacing) * targetIndex
// 使left
listLeftPosition.value = targetOffset + 'vw'
centerIndex.value = targetIndex
updatePosition() //
}
//
const handleTouchStart = (event) => {
touchStartX.value = event.touches[0].clientX
}
//
const handleTouchMove = (event) => {
touchEndX.value = event.touches[0].clientX
}
//
const handleTouchEnd = () => {
if (!touchStartX.value) return
let minSwipeDistance = 50 //x
let distance = touchEndX.value - touchStartX.value // <0 >0
let isLeftSwipe = distance < -minSwipeDistance //
let isRightSwipe = distance > minSwipeDistance //
if (isLeftSwipe) {
//
if (centerIndex.value > 0) {
moveToCenter(centerIndex.value - 1)
}
} else if (isRightSwipe) {
//
if (centerIndex.value < seasonTop1List.value.length - 1) {
moveToCenter(centerIndex.value + 1)
}
}
//
touchStartX.value = 0
touchEndX.value = 0
}
//
const updatePosition = () => {
const itemWidth = 40 // vw
const itemSpacing = 2 // vw
const targetOffset = (itemWidth + itemSpacing) * centerIndex.value
listLeftPosition.value = targetOffset + 'vw'
}
//