[bugfix] Tab: scroll position after activated (#1512)

This commit is contained in:
neverland 2018-07-19 21:14:45 +08:00 committed by GitHub
parent b7b2ad9ffc
commit 191f983e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,13 +126,14 @@ export default create({
this.$nextTick(() => { this.$nextTick(() => {
this.handlers(true); this.handlers(true);
this.scrollIntoView(); this.scrollIntoView(true);
}); });
}, },
activated() { activated() {
this.$nextTick(() => { this.$nextTick(() => {
this.handlers(true); this.handlers(true);
this.scrollIntoView(true);
}); });
}, },
@ -258,7 +259,7 @@ export default create({
}, },
// scroll active tab into view // scroll active tab into view
scrollIntoView() { scrollIntoView(immediate) {
if (!this.scrollable || !this.$refs.tabs) { if (!this.scrollable || !this.$refs.tabs) {
return; return;
} }
@ -268,11 +269,16 @@ export default create({
const { scrollLeft, offsetWidth: navWidth } = nav; const { scrollLeft, offsetWidth: navWidth } = nav;
const { offsetLeft, offsetWidth: tabWidth } = tab; const { offsetLeft, offsetWidth: tabWidth } = tab;
this.scrollTo(nav, scrollLeft, offsetLeft - (navWidth - tabWidth) / 2); this.scrollTo(nav, scrollLeft, offsetLeft - (navWidth - tabWidth) / 2, immediate);
}, },
// animate the scrollLeft of nav // animate the scrollLeft of nav
scrollTo(el, from, to) { scrollTo(el, from, to, immediate) {
if (immediate) {
el.scrollLeft += to - from;
return;
}
let count = 0; let count = 0;
const frames = Math.round(this.duration * 1000 / 16); const frames = Math.round(this.duration * 1000 / 16);
const animate = () => { const animate = () => {