私はこれをずっと見つめていました、そしていくつかの助けが必要です。IEでは機能するがChromeでは機能しない次の簡略化されたフィドルの例があります(エラーはなく、Chromeでキャンバスがクリアされた後に画像が再描画されることはありません):
var myApp = {};
// redraw function that will be called during init and then will loop.
myApp.redrawFunction = function() {
window.requestAnimationFrame(myApp.redrawFunction);
// clear canvas (not needed in this simplified example, but I need it in my real app)
myApp.drawingContext.clearRect(0, 0, myApp.canvas.width, myApp.canvas.height);
// draw an image.
var myImage = new Image();
myImage.onload = function() {
myApp.drawingContext.drawImage(myImage, 0, 0);
};
myImage.src= "http://www.w3.org/html/logo/img/mark-word-icon.png";
};
// initialize
$(function () {
// setup the animation frame objects.
window.requestAnimationFrame = window.requestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame;
window.cancelAnimationFrame = window.CancelAnimationFrame
|| window.CancelRequestAnimationFrame
|| window.mozCancelAnimationFrame
|| window.mozCancelRequestAnimationFrame
|| window.msCancelAnimationFrame
|| window.msCancelRequestAnimationFrame
|| window.webkitCancelAnimationFrame
|| window.webkitCancelRequestAnimationFrame;
// get canvas references.
myApp.canvas = $("canvas")[0];
myApp.drawingContext = myApp.canvas.getContext("2d");
$(myApp.canvas).css("background-color", "#999999");
// update canvas size to fill screen.
myApp.canvas.width = $(window).width();
myApp.canvas.height = $(window).height();
$(window).resize(function (){
myApp.canvas.width = $(window).width();
myApp.canvas.height = $(window).height();
});
// start redraw loop
myApp.redrawFunction();
});
このフィドルをIE10で開くと、機能します(ロゴが表示されます)。これをChromeで開くと、空白のキャンバスが表示され、キャンバスをクリアした後、drawImage呼び出しが機能しなかったことを示しています。私が欠けているアイデアはありますか?