calc-animate-val
v1.1.0
Published
根据总时长、当前时间、缓动函数来计算动画元素每次执行时所在的位置。
Downloads
23
Readme
calcAnimateVal
npm i calc-animate-val
根据总时长、当前时间、缓动函数来计算动画元素每次执行时所在的位置。使用requestAnimationFrame执行动画,获取当前时间。在不支持rAf的平台,需要自行polyfill rAF。
实例:一键回到顶部
import calcAnimateVal from 'calc-animate-val'
const { run, pause, done } = calcAnimateVal({
position: [document.documentElement.scrollTop, 0],
duration: 2000,
timingFn: 'easeOutQuint',
delay: 0,
running: y => window.scrollTo(0, y),
done: () => alert('动画完成')
})
run() // 执行
pause() // 暂停
done() // 立即中断动画
指南
interface CalcAnimateVal {
(opt: Options): CalcFnResult
rAF: any
cancelRAF: any
}