|
|
@@ -21,19 +21,16 @@ async function getDataList() {
|
|
|
}
|
|
|
function handleSelect(categoryId: string) {
|
|
|
activeCategory.value = categoryId
|
|
|
- // 滚动到对应分类位置
|
|
|
- console.log(11, categoryRefs.value)
|
|
|
//找到第一个元素上categoryId属性与categoryId相同的元素
|
|
|
const element = categoryRefs.value.find((item: any) => {
|
|
|
return item.dataset.category === categoryId
|
|
|
})
|
|
|
- console.log(11, element)
|
|
|
if (element) {
|
|
|
const rect = element.getBoundingClientRect()
|
|
|
console.log(rect)
|
|
|
if (cardsScrollView.value) {
|
|
|
cardsScrollView.value.scrollTo({
|
|
|
- top: rect.top, // 减去顶部偏移
|
|
|
+ top: rect.top - 70, // 减去顶部偏移
|
|
|
animated: true
|
|
|
})
|
|
|
}
|
|
|
@@ -44,7 +41,9 @@ function onScroll(e: any) {
|
|
|
const scrollTop = e.detail.scrollTop
|
|
|
// 遍历所有分类,检查哪个分类在可视区域
|
|
|
for (const category of categories.value) {
|
|
|
- const element = categoryRefs.value[category.id]
|
|
|
+ const element = categoryRefs.value.find((item: any) => {
|
|
|
+ return item.dataset.category === category.id
|
|
|
+ })
|
|
|
if (element) {
|
|
|
const rect = element.getBoundingClientRect()
|
|
|
// 检查元素是否在可视区域内
|