fix(Sticky): shoud rerender after visibility changed (#5888)
This commit is contained in:
+21
-1
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user