adui
Version:
<div> <img src="https://wxa.wxs.qq.com/mpweb/delivery/legacy/wxadtouch/upload/t1/od834zef_52939fc6.png" style="margin:40px 0 0 -8px; background-color: #fcfcfc; box-shadow: none;" /> </div>
27 lines (24 loc) • 679 B
text/typescript
type ICb = (time: number) => void
function requestAnimationFramePolyfill() {
let lastTime = 0
return (callback: ICb) => {
const currTime = new Date().getTime()
const timeToCall = Math.max(0, 16 - (currTime - lastTime))
const id = window.setTimeout(() => {
callback(currTime + timeToCall)
}, timeToCall)
lastTime = currTime + timeToCall
return id
}
}
function getRequestAnimationFrame() {
if (typeof window === "undefined") {
return () => {}
}
const { requestAnimationFrame } = window
if (requestAnimationFrame) {
return requestAnimationFrame
}
return requestAnimationFramePolyfill()
}
export { getRequestAnimationFrame }