我正在尝试使用 HTML5 画布为牛制作一个简单的动画。该代码适用于 Google Chrome,但不适用于 Mozilla Firefox、Safari 等。我的功能(代码)如下所示:
function animalView(objectToMove) {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
this.a = 0;
(function() {
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
(function drawFrame() {
window.requestAnimationFrame(drawFrame, canvas);
context.save();
context.clearRect(0, 0, canvas.width, canvas.height);
this.a += 10;
objectToMove.tail = Math.sin( this.a );
objectToMove.draw(context);
context.restore();
}());
}
我注意到this.a
当回调函数调用function()
.