mirror of https://github.com/ElemeFE/element
Tabs: scroll to active tab (#12948)
* Tabs: fix not scrolling to active tab * update tabs.vuepull/12950/head
parent
7e29e1c66d
commit
80410b4487
|
@ -87,7 +87,7 @@
|
||||||
const navScroll = this.$refs.navScroll;
|
const navScroll = this.$refs.navScroll;
|
||||||
const activeTabBounding = activeTab.getBoundingClientRect();
|
const activeTabBounding = activeTab.getBoundingClientRect();
|
||||||
const navScrollBounding = navScroll.getBoundingClientRect();
|
const navScrollBounding = navScroll.getBoundingClientRect();
|
||||||
const navBounding = nav.getBoundingClientRect();
|
const maxOffset = nav.offsetWidth - navScrollBounding.width;
|
||||||
const currentOffset = this.navOffset;
|
const currentOffset = this.navOffset;
|
||||||
let newOffset = currentOffset;
|
let newOffset = currentOffset;
|
||||||
|
|
||||||
|
@ -97,10 +97,9 @@
|
||||||
if (activeTabBounding.right > navScrollBounding.right) {
|
if (activeTabBounding.right > navScrollBounding.right) {
|
||||||
newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
|
newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
|
||||||
}
|
}
|
||||||
if (navBounding.right < navScrollBounding.right) {
|
|
||||||
newOffset = nav.offsetWidth - navScrollBounding.width;
|
newOffset = Math.max(newOffset, 0);
|
||||||
}
|
this.navOffset = Math.min(newOffset, maxOffset);
|
||||||
this.navOffset = Math.max(newOffset, 0);
|
|
||||||
},
|
},
|
||||||
update() {
|
update() {
|
||||||
if (!this.$refs.nav) return;
|
if (!this.$refs.nav) return;
|
||||||
|
|
|
@ -45,8 +45,10 @@
|
||||||
},
|
},
|
||||||
currentName(value) {
|
currentName(value) {
|
||||||
if (this.$refs.nav) {
|
if (this.$refs.nav) {
|
||||||
this.$nextTick(_ => {
|
this.$nextTick(() => {
|
||||||
this.$refs.nav.scrollToActiveTab();
|
this.$refs.nav.$nextTick(_ => {
|
||||||
|
this.$refs.nav.scrollToActiveTab();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue