fix(Tabs): failed to scroll into view when render multiple tabs (#9542)

This commit is contained in:
neverland 2021-09-22 16:01:51 +08:00 committed by GitHub
parent 91d65d4a64
commit cc2a40450e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,15 +1,11 @@
import { raf, cancelRaf } from '../utils/dom/raf'; import { raf } from '../utils/dom/raf';
import { getScrollTop, setScrollTop } from '../utils/dom/scroll'; import { getScrollTop, setScrollTop } from '../utils/dom/scroll';
let scrollLeftRafId: number;
export function scrollLeftTo( export function scrollLeftTo(
scroller: HTMLElement, scroller: HTMLElement,
to: number, to: number,
duration: number duration: number
) { ) {
cancelRaf(scrollLeftRafId);
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) {
scrollLeftRafId = raf(animate); raf(animate);
} }
} }