mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 02:16:12 +08:00
[bugfix] Tab: scroll position after activated (#1512)
This commit is contained in:
parent
b7b2ad9ffc
commit
191f983e19
@ -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 = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user