requestAnimationFrame.js后续学习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了requestAnimationFrame.js后续学习相关的知识,希望对你有一定的参考价值。
(function() { var lastTime = 0; var vendors = [‘webkit‘, ‘moz‘]; for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + ‘RequestAnimationFrame‘]; window.cancelAnimationFrame = window[vendors[x] + ‘CancelAnimationFrame‘] || // name has changed in Webkit window[vendors[x] + ‘CancelRequestAnimationFrame‘]; } if (!window.requestAnimationFrame) { window.requestAnimationFrame = function(callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16.7 - (currTime - lastTime)); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; }; } if (!window.cancelAnimationFrame) { window.cancelAnimationFrame = function(id) { clearTimeout(id); }; } }());
以上是关于requestAnimationFrame.js后续学习的主要内容,如果未能解决你的问题,请参考以下文章