아래 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();