以下内容导致错误(FF、Chrome和?):
Engine.prototype.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
完整的背景是:
var Engine = function(model) {
this.model = model;
};
Engine.prototype.start = function() {
console.log("ready")
this.requestAnimationFrame(function() {
console.log("done");
});
};
Engine.prototype.updateUi = function() {
console.log("update ui");
this.requestAnimationFrame(this.updateUi);
};
Engine.prototype.logRAF = function() {
console.log(window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame);
return this;
};
Engine.prototype.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
var engine = new Engine();
engine.logRAF().start();
FF -mozRequestAnimationFrame()中的错误如下:NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object
Chrome -webkitRequestAnimationFrame()中的错误如下:Uncaught TypeError: Illegal invocation
在线路上:
this.requestAnimationFrame...
日志将打印出“就绪”,但不显示“已完成”。
如果我只使用一个函数而不是本机RAF方法,它就能工作(“已完成”被记录):
RequestAnimationFrames是怎么回事?
发布于 2012-12-28 11:14:14
发布于 2012-12-28 11:18:11
requestAnimationFrame
应该在window
:this.requestAnimationFrame.call(window, ...);
的上下文中调用,如这里所提到的:Chrome中的“未登录TypeError:非法调用”
https://stackoverflow.com/questions/14068436
复制相似问题