Suppose I'm starting with the requestAnimationFrame shim by Paul Irish:

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

and I'm running on OS X Mavericks, and I want to make changes to the shim - for example:

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;

Now to test this shim and make sure it works on Mavericks - I need a browser that this shim applies to. By default my browsers are Chrome 31 and Firefox 24. (For which this shim is redundant)

My question is how do I test changes to a requestAnimationFrame shim on OSX Mavericks?

有帮助吗?

解决方案

To test you can clear the native one:

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

... run shim here...

BTW You also need to make your shim self-invoking:

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

See demo here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top