🎨 重构滚动高度计算

This commit is contained in:
目棃
2025-03-07 15:13:20 +08:00
parent d32d7b69f1
commit dd3ce101a6

View File

@@ -76,11 +76,11 @@ watch(
async () => {
if (visible.value && posts.value.length > 0) {
await nextTick();
if (postListEl.value === null || props.collection.total < 5) return;
let topNum: number;
if (props.collection.total - props.collection.cur < 3) topNum = props.collection.total;
else topNum = props.collection.cur - 3;
postListEl.value.scrollTo({ top: topNum * 87, behavior: "smooth" });
if (postListEl.value === null) return;
const selectedEl = document.querySelector<HTMLDivElement>(".tpoc-item.selected");
if (selectedEl === null) return;
const scrollHeight = selectedEl.offsetTop - postListEl.value.offsetTop;
postListEl.value.scrollTo({ top: scrollHeight, behavior: "smooth" });
}
},
);