Skip to content

Commit

Permalink
fix(Tab): "scrollLeftTo" function could not handle decimal correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pany-ang authored Jun 8, 2024
1 parent 31aae0b commit eb0073c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vant/src/tabs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export function scrollLeftTo(
let count = 0;
const from = scroller.scrollLeft;
const frames = duration === 0 ? 1 : Math.round((duration * 1000) / 16);
let scrollLeft = from;

function cancel() {
cancelRaf(rafId);
}

function animate() {
scroller.scrollLeft += (to - from) / frames;
scrollLeft += (to - from) / frames;
scroller.scrollLeft = scrollLeft;

if (++count < frames) {
rafId = raf(animate);
Expand Down

0 comments on commit eb0073c

Please sign in to comment.