From 017c4be9e8ea2a81b38c0ae7e4da8c58401d8ec8 Mon Sep 17 00:00:00 2001 From: johnsonwong666 <1067100250@qq.com> Date: Wed, 12 Apr 2023 14:09:49 +0800 Subject: [PATCH] fix(Sticky): fix sticky wrap empty --- packages/sticky/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/sticky/index.ts b/packages/sticky/index.ts index b433e281f..0b0906352 100644 --- a/packages/sticky/index.ts +++ b/packages/sticky/index.ts @@ -49,6 +49,7 @@ VantComponent({ mounted() { this.onScroll(); + this.observeWrap(); }, methods: { @@ -130,5 +131,16 @@ VantComponent({ (resolve) => nodesRef.boundingClientRect(resolve).exec() ); }, + + observeWrap() { + // 如果子元素没有内容了 高度为0 取消掉fixed + const observer = wx.createIntersectionObserver(this); + observer.relativeToViewport(); + observer.observe(`.van-sticky-wrap`, (res) => { + if (!res.boundingClientRect.height) { + this.setDataAfterDiff({ fixed: false, height: 0 }); + } + }); + }, }, });