0.0.3 • Published 10 months ago

raf-es v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

说明

对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]
}
0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago