我想只是做一個矩形,但沒有什麼會出現,只是背景。我已經試過ctx.fill,ctx.fillStyle等沒有什麼作品:Javascript沒有形狀出現
我指的這部分
fill(77, 66, 66);
rect(10,200,100,100);
下面是頁面
var ctx, W, H;
window.onload = function() {
var canvas = document.getElementById("canvas");
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
ctx = canvas.getContext("2d");
setInterval(draw, 1);
function draw() {
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = "#E6E6FF"; // this part does appear
ctx.fillRect(0, 0, W, H);
fill(77, 66, 66); // this doesn't appear
rect(10,200,100,100);
}
}
整個代碼由於
它不應該是ctx.fill和ctx.rect? – toskv
我也嘗試過這些(請參閱開始發佈) – zigg75483
我認爲你應該[後退](http://stackoverflow.com/questions/32784673/javascript-not-showing-up-in-browser/32784727#32784727)並閱讀[畫布教程](http://www.html5canvastutorials.com/),@ zigg75483 – Scott