Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Sticky): fix sticky wrap empty #5325

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/sticky/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ VantComponent({

mounted() {
this.onScroll();
this.observeWrap();
},

methods: {
Expand Down Expand Up @@ -130,5 +131,16 @@ VantComponent({
(resolve) => nodesRef.boundingClientRect(resolve).exec()
);
},

observeWrap() {
// 如果子元素没有内容了 高度为0 取消掉fixed
const observer = wx.createIntersectionObserver(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两个问题

  1. 监听需要在组件卸载时回收
  2. 有没有更好的办法,监听回调在滚动时是否会触发?需要考虑一定的性能问题

observer.relativeToViewport();
observer.observe(`.van-sticky-wrap`, (res) => {
if (!res.boundingClientRect.height) {
this.setDataAfterDiff({ fixed: false, height: 0 });
}
});
},
},
});