This commit is contained in:
Kang Cheng 2017-10-29 15:39:45 -07:00
parent 7a9f6b28fc
commit 79885751e2

View file

@ -310,6 +310,16 @@
}, },
handleResize(){ handleResize(){
this.updateNavScroll(); this.updateNavScroll();
},
isInsideHiddenElement () {
let parentNode = this.$el.parentNode;
while(parentNode) {
if (parentNode.style.display === 'none') {
return parentNode;
}
parentNode = parentNode.parentNode;
}
return false;
} }
}, },
watch: { watch: {
@ -329,6 +339,18 @@
this.showSlot = this.$slots.extra !== undefined; this.showSlot = this.$slots.extra !== undefined;
this.observer = elementResizeDetectorMaker(); this.observer = elementResizeDetectorMaker();
this.observer.listenTo(this.$refs.navWrap, this.handleResize); this.observer.listenTo(this.$refs.navWrap, this.handleResize);
const hiddenParentNode = this.isInsideHiddenElement();
if (hiddenParentNode) {
const mutationObserver = new MutationObserver(() => {
if (hiddenParentNode.style.display !== 'none') {
this.updateBar();
mutationObserver.disconnect();
}
});
mutationObserver.observe(hiddenParentNode, { attributes: true, childList: true, characterData: true, attributeFilter: ['style'] });
}
}, },
beforeDestroy() { beforeDestroy() {
this.observer.removeListener(this.$refs.navWrap, this.handleResize); this.observer.removeListener(this.$refs.navWrap, this.handleResize);