我想設置一個.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>
如果我的回答很有幫助,請將其標記爲已接受。 –