我想设置一个.gif图像作为画布的背景图像,以便我可以获得背景的动画视图。但是我只能看到显示在其上的静态图像。.gif图像作为画布背景
这是我的Windows 8应用程序的HTML代码。
<body>
<canvas id="canvas"></canvas>
<img id="scream" src="images/gangam.gif" alt="The Scream" width="220" height="277">
</body>
<script>
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"); // Create canvas context
function paintCanvas() {
ctx.fillStyle = "white";
ctx.fillRect(0, 0, W, H);
var img = document.getElementById("scream");
ctx.drawImage(img, W/2, H/2);
}
</script>
如果我的回答很有帮助,请将其标记为已接受。 –