Преглед на файлове

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

icssoa преди 4 месеца
родител
ревизия
19b7435421
променени са 1 файла, в които са добавени 31 реда и са изтрити 26 реда
  1. 31 26
      uni_modules/cool-ui/components/cl-sticky/cl-sticky.uvue

+ 31 - 26
uni_modules/cool-ui/components/cl-sticky/cl-sticky.uvue

@@ -105,32 +105,37 @@ const stickyTop = computed(() => {
 
 // 获取sticky元素的位置信息,并更新rect
 function getRect() {
-	nextTick(() => {
-		setTimeout(
-			() => {
-				uni.createSelectorQuery()
-					.in(proxy)
-					.select(".cl-sticky")
-					.boundingClientRect()
-					.exec((nodes) => {
-						if (isEmpty(nodes)) {
-							return;
-						}
-
-						const node = nodes[0] as NodeInfo;
-
-						// 赋值时做空值处理,保证类型安全
-						rect.height = node.height ?? 0;
-
-						rect.width = node.width ?? 0;
-						rect.left = node.left ?? 0;
-						// top需要减去offsetTop并加上当前滚动距离,保证吸顶准确
-						rect.top = (node.top ?? 0) - props.offsetTop + scrollTop.value;
-					});
-			},
-			isHarmony() ? 300 : 0
-		);
-	});
+	const next = () => {
+		uni.createSelectorQuery()
+			.in(proxy)
+			.select(".cl-sticky")
+			.boundingClientRect()
+			.exec((nodes) => {
+				if (isEmpty(nodes)) {
+					return;
+				}
+
+				const node = nodes[0] as NodeInfo;
+
+				// 赋值时做空值处理,保证类型安全
+				rect.height = node.height ?? 0;
+
+				rect.width = node.width ?? 0;
+				rect.left = node.left ?? 0;
+				// top需要减去offsetTop并加上当前滚动距离,保证吸顶准确
+				rect.top = (node.top ?? 0) - props.offsetTop + scrollTop.value;
+			});
+	};
+
+	if (isHarmony()) {
+		nextTick(() => {
+			setTimeout(() => {
+				next();
+			}, 300);
+		});
+	} else {
+		next();
+	}
 }
 
 onMounted(() => {