fix(utils): streamline scroll animation logic in springScrollTo

- Removed unnecessary requestAnimationFrame handling to simplify the scroll animation process.
- Enhanced the stopping condition for animations to ensure smoother transitions during scrolling.

These changes improve the efficiency and responsiveness of the scrolling behavior.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2025-05-22 14:18:28 +08:00
parent 70da1ab94b
commit 4f7158e287
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 5 additions and 9 deletions

View File

@ -20,7 +20,7 @@ export const springScrollTo = (
isStop = true
animation.stop()
}
let raf: any
const el = scrollerElement || window
const animation = animateValue({
keyframes: [scrollTop + 1, y],
@ -34,18 +34,14 @@ export const springScrollTo = (
onUpdate(latest) {
if (latest <= 0) {
animation.stop()
return
}
if (raf) {
cancelAnimationFrame(raf)
if (isStop) {
return
}
raf = requestAnimationFrame(() => {
if (isStop) {
return
}
el.scrollTo(0, latest)
})
el.scrollTo(0, latest)
},
})