<!DOCTYPE html5>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS3-Canvas畫布(圖形-三角形)</title>
<script>
window.onload=function () {
var canvas=document.getElementById("canvas");//獲取canvas對象
var ctx=canvas.getContext("2d"); //創建二維的繪圖上下文對象
ctx.beginPath();
ctx.linewidth=20;
ctx.lineJoin="round"; //兩條線交匯時的邊角類型(miter 尖角默認 bevel斜角 round 圓角 )
ctx.moveTo(10,10);
ctx.lineTo(100,100);
ctx.lineTo(400,10);
// ctx.lineTo(10,10);
ctx.closePath(); //closePath() 關閉路徑 閉合
ctx.strokeStyle="blue";// strokeStyle 只能填充該路徑的顏色
ctx.fillStyle="red";// fillStyle 填充字體顏色、填充路徑區域、圖形區域
ctx.fill();// fill() 填充字體
ctx.stroke();
}
</script>
</head>
<body>
<h2>Canvas畫布(圖形)</h2>
<canvas id="canvas" width="500" height="500" style="border:1px solid red ">
瀏覽器不支持canvas
</canvas>
</body>
</html>