raf-es
v0.0.3
Published
对raf库进行改造,支持(esm,cjs,umd)
Downloads
2
Maintainers
Readme
说明
对raf库进行了升级补充说明
支持esm,cjs,umd引入方式.
更丝滑的requestAnimationFrame使用体验
如何使用
// import方式引入 //
import raf from 'raf-es'
// hooks版
export const useRef = cb => {
let animationId = null
const startAnimation = () => {
const animate = () => {
cb?.()
animationId = raf(animate)
}
animationId = raf(animate)
}
const cancelAnimation = () => {
raf.cancel(animationId)
}
return [startAnimation, cancelAnimation]
}
// require方式引入 //
export const useRaf = cb => {
const raf = require('raf')
let animationId = null
const startAnimation = () => {
const animate = () => {
cb?.()
animationId = raf(animate)
}
animationId = raf(animate)
}
const cancelAnimation = () => {
raf.cancel(animationId)
}
return [startAnimation, cancelAnimation]
}