<!DOCTYPE html><head>
<meta charset=utf-8>
<title>HTML5畫線、圓、矩形</title>
<script src="<a ></script</a>>
</head>
<script>
$(document).ready(function(){
var c=document.getElementById("drawbox");
var draw=c.getContext("2d"); //獲取2d內容的引用,調用繪圖API</p>
<p>//指定漸變區(qū)塊
var grd=draw.createLinearGradient(50,50,200,50); //坐標,長寬
grd.addColorStop(0,"black"); //起點顏色
grd.addColorStop(1,"green"); //終點顏色</p>
<p>draw.fillStyle=grd; //設為填充樣式
draw.fillRect(50,50,200,50); //填充進矩形內
})
</script>
</body>
<canvas id="drawbox" width="500" height="500"></canvas>
</body>
</html>
效果圖: