diff --git a/app/app/components/auto-scroll-controls.tsx b/app/app/components/auto-scroll-controls.tsx index fb830c1..77c65c3 100644 --- a/app/app/components/auto-scroll-controls.tsx +++ b/app/app/components/auto-scroll-controls.tsx @@ -24,14 +24,21 @@ export function AutoScrollControls({ scrollRef }: Props) { const lastTimeRef = useRef(0); const cancelledByUser = useRef(false); + const accumulatorRef = useRef(0); + const tick = useCallback( (time: number) => { - if (!scrollRef.current) return; + const el = scrollRef.current; + if (!el) return; if (lastTimeRef.current) { const dt = (time - lastTimeRef.current) / 1000; - scrollRef.current.scrollTop += speed * dt; + accumulatorRef.current += speed * dt; + const px = Math.floor(accumulatorRef.current); + if (px >= 1) { + accumulatorRef.current -= px; + el.scrollBy({ top: px }); + } - const el = scrollRef.current; if (el.scrollTop + el.clientHeight >= el.scrollHeight - 1) { setPlaying(false); return; @@ -46,6 +53,7 @@ export function AutoScrollControls({ scrollRef }: Props) { useEffect(() => { if (playing) { lastTimeRef.current = 0; + accumulatorRef.current = 0; cancelledByUser.current = false; rafRef.current = requestAnimationFrame(tick); } else {