requstAnimationFrame
作者:互联网
- 问题:执行动画,用定时器的话会有什么问题,用requstAnimationFrame比定时器好在哪里
- 遇到的问题:时间间隔不定,卡顿,这些问题都是因为,定时器的任务并不是时间到了就立即执行,而是放到一部队列里,所以执行时间是不可靠的
- requstAnimationFrame它以动画帧作为标志,而用定时器实现的动画,如果把最小化或者切换到其他页面,这个页面还在运行,此时刷新动画是没有意义的,浪费CUP;如果离开的时候暂停动画,然后回来的那一刻回复动画,requstAnimationFrame也能做的到,还起到节流的节流的作用,
- 总结:防丢帧、CPU节能、函数节流、减少DOM操作
标签:动画,定时器,节流,requstAnimationFrame,执行,页面 来源: https://www.cnblogs.com/CHEN-JING-YANG/p/16481848.html