修复top=0的组件无法吸附问题

This commit is contained in:
icssoa
2025-11-13 22:34:34 +08:00
parent 629652c500
commit 19b7435421

View File

@@ -105,9 +105,7 @@ const stickyTop = computed(() => {
// 获取sticky元素的位置信息并更新rect // 获取sticky元素的位置信息并更新rect
function getRect() { function getRect() {
nextTick(() => { const next = () => {
setTimeout(
() => {
uni.createSelectorQuery() uni.createSelectorQuery()
.in(proxy) .in(proxy)
.select(".cl-sticky") .select(".cl-sticky")
@@ -127,10 +125,17 @@ function getRect() {
// top需要减去offsetTop并加上当前滚动距离保证吸顶准确 // top需要减去offsetTop并加上当前滚动距离保证吸顶准确
rect.top = (node.top ?? 0) - props.offsetTop + scrollTop.value; rect.top = (node.top ?? 0) - props.offsetTop + scrollTop.value;
}); });
}, };
isHarmony() ? 300 : 0
); if (isHarmony()) {
nextTick(() => {
setTimeout(() => {
next();
}, 300);
}); });
} else {
next();
}
} }
onMounted(() => { onMounted(() => {