如何在OSX Mavericks上测试对requestAnimationFrame垫片的更改?

时间:2014-01-17 05:48:47

标签: javascript html5 macos html5-canvas requestanimationframe

假设我从requestAnimationFrame shim by Paul Irish开始:

window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame       ||
          window.webkitRequestAnimationFrame ||
          window.mozRequestAnimationFrame    ||
          function( callback ){
            window.setTimeout(callback, 1000 / 60);
          };
})();

我在OS X Mavericks上运行,我想对垫片进行更改 - 例如:

var myfunc = function() {
    if (typeof(window.requestAnimationFrame) != "undefined") {
        return window.requestAnimationFrame;
    } else if (typeof(window.webkitRequestAnimationFrame) != "undefined") {
        return window.webkitRequestAnimationFrame;
    } else if (typeof(window.mozRequestAnimationFrame) != "undefined") {
        return window.mozRequestAnimationFrame;
    } else {
        return function(callback) {
            window.setTimeout(callback, 1000 / 60);
        };
    }
};
window.requestAnimFrame = myfunc;

现在测试这个垫片并确保它适用于Mavericks - 我需要一个这个垫片适用的浏览器。默认情况下,我的浏览器是Chrome 31和Firefox 24.(For which this shim is redundant

我的问题是如何在OSX Mavericks上测试对requestAnimationFrame垫片的更改?

1 个答案:

答案 0 :(得分:0)

测试,您可以清除原生的

window.requestAnimationFrame = undefined;
window.mozRequestAnimationFrame = undefined;
window.webkitRequestAnimationFrame = undefined;

... run shim here...

BTW你还需要让你的垫片自我调用:

var myfunc = (function() { ... })();

请参阅 demo here