From 15836f3b1ebb7338a2cefa4e9576c7f403f710e3 Mon Sep 17 00:00:00 2001 From: Sociosarbis <136657577@qq.com> Date: Tue, 10 Dec 2019 00:19:28 +0800 Subject: [PATCH] fix: tab can't scroll to the right position --- src/components/tab/tab.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/tab/tab.vue b/src/components/tab/tab.vue index d68f6fcca..1c9d0dce1 100755 --- a/src/components/tab/tab.vue +++ b/src/components/tab/tab.vue @@ -133,11 +133,11 @@ export default { } const currentIndexTab = this.$children[this.currentIndex].$el let count = 0 + const scrollDuration = 15 // scroll animation const step = () => { - const scrollDuration = 15 const nav = this.$refs.nav - nav.scrollLeft += (currentIndexTab.offsetLeft - (nav.offsetWidth - currentIndexTab.offsetWidth) / 2 - nav.scrollLeft) / scrollDuration + nav.scrollLeft += (currentIndexTab.offsetLeft - (nav.offsetWidth - currentIndexTab.offsetWidth) / 2 - nav.scrollLeft) / (scrollDuration - count) if (++count < scrollDuration) { window.requestAnimationFrame(step) }