mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
18 lines
382 B
TypeScript
18 lines
382 B
TypeScript
import { raf } from '../utils/dom/raf';
|
|
|
|
export function scrollLeftTo(el: HTMLElement, to: number, duration: number) {
|
|
let count = 0;
|
|
const from = el.scrollLeft;
|
|
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
|
|
|
|
function animate() {
|
|
el.scrollLeft += (to - from) / frames;
|
|
|
|
if (++count < frames) {
|
|
raf(animate);
|
|
}
|
|
}
|
|
|
|
animate();
|
|
}
|