mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Fix blocked animate when running in background (#80)
This commit is contained in:
@@ -19,12 +19,20 @@ const easeOutQuad = x => 1 - (1 - x) * (1 - x)
|
||||
const animate = (a, b, duration, ease, render) => new Promise(resolve => {
|
||||
let start
|
||||
const step = now => {
|
||||
if (document.hidden) {
|
||||
render(lerp(a, b, 1))
|
||||
return resolve()
|
||||
}
|
||||
start ??= now
|
||||
const fraction = Math.min(1, (now - start) / duration)
|
||||
render(lerp(a, b, ease(fraction)))
|
||||
if (fraction < 1) requestAnimationFrame(step)
|
||||
else resolve()
|
||||
}
|
||||
if (document.hidden) {
|
||||
render(lerp(a, b, 1))
|
||||
return resolve()
|
||||
}
|
||||
requestAnimationFrame(step)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user