下面的URL中有一個很小的示例,繪製兩行。我期望頂線是綠色,底部是藍色。但他們都是藍色的。爲什麼?HTML 5畫布風格泄漏
編輯添加下面的腳本,以及:
var canvas = document.getElementById('canvas');
canvas.width = 500;
canvas.height = 500;
var ctx = canvas.getContext('2d');
ctx.globalAlpha = 1;
ctx.globalCompositeOperation = "source-over";
var x1=10, y1=10, width=100, height=100;
ctx.lineWidth = "5";
//draw green line
ctx.strokeStyle = "#00FF00";
ctx.moveTo(x1 + 1, y1 + 1);
ctx.lineTo(x1 + width - 2, y1 + 1);
ctx.stroke();
//draw blue line
ctx.strokeStyle = "#0000FF";
ctx.moveTo(x1 + 1, y1 + 10);
ctx.lineTo(x1 + width - 2, y1 + 10);
ctx.stroke();