window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000/60); }; })(); //调用 function animationLoop(elem){ requestAnimFrame(animationLoop); //logic } Or window.requestAnimFrame = (function(w, r) { w['r'+r] = w['r'+r] || w['webkitR'+r] || w['mozR'+r] || w['msR'+r] || w['oR'+r] || function(c){ w.setTimeout(c, 1000 / 60); }; return w['r'+r]; })(window, 'equestAnimationFrame');
以上通过两段代码示例详解说明了使用requestAnimationFrame实现js动画性能好,希望大家喜欢。
您可能感兴趣的文章: