perf(tangPopup): 优化滚动定位逻辑

- 移除了 setTimeout 包裹,直接执行滚动定位逻辑
- 保留了原有的滚动定位功能,没有引入新功能
This commit is contained in:
xingyy 2025-02-08 17:10:23 +08:00
parent ad19345db6
commit f1bd2b183f

View File

@ -33,25 +33,22 @@ const props = defineProps({
})
const scrollToCurrentItem = () => {
if (!itemList.value?.length) return
setTimeout(() => {
const currentIndex = itemList.value.findIndex(
item => auctionData.value.artwork.index === item?.index
)
if (currentIndex > -1) {
const container = document.querySelector('.list-container')
const targetElement = document.querySelectorAll('.item-wrapper')[currentIndex]
if (targetElement && container) {
const containerTop = container.getBoundingClientRect().top
const elementTop = targetElement.getBoundingClientRect().top
const scrollTop = elementTop - containerTop + container.scrollTop
container.scrollTo({
top: scrollTop,
behavior: 'smooth'
})
}
const currentIndex = itemList.value.findIndex(
item => auctionData.value.artwork.index === item?.index
)
if (currentIndex > -1) {
const container = document.querySelector('.list-container')
const targetElement = document.querySelectorAll('.item-wrapper')[currentIndex]
if (targetElement && container) {
const containerTop = container.getBoundingClientRect().top
const elementTop = targetElement.getBoundingClientRect().top
const scrollTop = elementTop - containerTop + container.scrollTop
container.scrollTo({
top: scrollTop,
behavior: 'smooth'
})
}
}, 100)
}
}
const emit = defineEmits(['update:show'])
const showDetailInfo=ref(null)