DOM动画的一些优化
对一些DOM绘制进行节流,防重复,防抖,以性能优化
硬节流
// Some code
// Some code
const throttleByAnimationFrame = (func) => {
let callArgs = null
const frameFunc = () => {
const currentCallArgs = callArgs
callArgs = null
func.apply(null, currentCallArgs)
}
return (...args) => {
!callArgs && requestAnimationFrame(frameFunc) //防止一个渲染进程中多次注册
callArgs = args
}
}
var sayNum = throttleByAnimationFrame((a,b,c)=>{console.log(a,b,c)})
选择性节流
window.requestAnimationFrame(callback);
返回值
最后更新于