# raf-es **Repository Path**: organize-some-projects/raf-es ## Basic Information - **Project Name**: raf-es - **Description**: es模块化的raf - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-11-28 - **Last Updated**: 2023-11-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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] } ```