下面的 URL 中有一个小示例,它画了两条线。我希望顶线是绿色,底部是蓝色。但它们都是蓝色的。为什么?
编辑 也添加下面的脚本:
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();