fix(Tabs): failed to scroll into view when rendering multiple tabs (#9543)

This commit is contained in:
neverland 2021-09-22 16:03:22 +08:00 committed by GitHub
parent 99dcbc04f8
commit 38b1be3ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,15 +1,11 @@
import { raf, cancelRaf } from '@vant/use'; import { raf } from '@vant/use';
import { ScrollElement, getScrollTop, setScrollTop } from '../utils'; import { ScrollElement, getScrollTop, setScrollTop } from '../utils';
let rafId: number;
export function scrollLeftTo( export function scrollLeftTo(
scroller: HTMLElement, scroller: HTMLElement,
to: number, to: number,
duration: number duration: number
) { ) {
cancelRaf(rafId);
let count = 0; let count = 0;
const from = scroller.scrollLeft; const from = scroller.scrollLeft;
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16); const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
@ -18,7 +14,7 @@ export function scrollLeftTo(
scroller.scrollLeft += (to - from) / frames; scroller.scrollLeft += (to - from) / frames;
if (++count < frames) { if (++count < frames) {
rafId = raf(animate); raf(animate);
} }
} }