基于RAF的一个小动画框
生活随笔
收集整理的這篇文章主要介紹了
基于RAF的一个小动画框
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
RAF也即是requestAnimationFrame,之前的動畫都是基于setTimeout寫的,所以為了性能方面的考慮,開始使用requestAnimationFrame寫動畫。
function animation(obj, data) {if (obj.timer) {window.cancelAnimationFrame(obj.timer)}obj.timer = window.requestAnimationFrame(function () {for (var i in data) {var current=parseInt(obj.style[i]);var target=parseInt(data[i]);var speed=(target-current)/8;speed=speed>0?Math.ceil(speed):Math.floor(speed);if(current!=target){obj.style[i]=current+speed+"px";obj.timer=window.requestAnimationFrame(arguments.callee);}}}) }?
轉載于:https://www.cnblogs.com/jelly7723/p/5513782.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的基于RAF的一个小动画框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 基础,包括列表,元组,字典
- 下一篇: JS 入门经典 第三章 判断、循环和