fix(Sticky): shoud rerender after visibility changed (#5888)

This commit is contained in:
neverland
2020-03-23 18:35:24 +08:00
committed by GitHub
parent a11a8e8f8c
commit 7ae3a4a1b1
2 changed files with 86 additions and 1 deletions
+21 -1
View File
@@ -7,11 +7,16 @@ const [createComponent, bem] = createNamespace('sticky');
export default createComponent({
mixins: [
BindEventMixin(function(bind) {
BindEventMixin(function(bind, isBind) {
if (!this.scroller) {
this.scroller = getScroller(this.$el);
}
if (this.observer) {
const method = isBind ? 'observe' : 'unobserve';
this.observer[method](this.$el);
}
bind(this.scroller, 'scroll', this.onScroll, true);
this.onScroll();
}),
@@ -58,6 +63,21 @@ export default createComponent({
},
},
created() {
// compatibility: https://caniuse.com/#feat=intersectionobserver
if (window.IntersectionObserver) {
this.observer = new IntersectionObserver(
entries => {
// trigger scroll when visibility changed
if (entries[0].intersectionRatio > 0) {
this.onScroll();
}
},
{ root: document.body }
);
}
},
methods: {
onScroll() {
if (isHidden(this.$el)) {