假设我从 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 上运行,并且我想对 shim 进行更改 - 例如:
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 shim 的更改?
最佳答案
要测试,您可以清除 native :
window.requestAnimationFrame = undefined;
window.mozRequestAnimationFrame = undefined;
window.webkitRequestAnimationFrame = undefined;
... run shim here...
顺便说一句,您还需要使您的垫片自调用:
var myfunc = (function() { ... })();
参见demo here 。
关于javascript - 如何在 OSX Mavericks 上测试对 requestAnimationFrame shim 的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21178782/