简体   繁体   中英

How do I test changes to a requestAnimationFrame shim on OSX Mavericks?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM