mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-29 20:29:46 +08:00
fix(Tabs): failed to scroll into view when rendering multiple tabs (#9543)
This commit is contained in:
parent
99dcbc04f8
commit
38b1be3ac2
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user