復制代碼代碼如下:
<!DOCTYPE Html><head>
<meta charset=utf-8>
<title>Html5畫線、圓、矩形</title>
<script src="<a href="http://AJax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.JS"></script">http://ajax.googleapis.com/AJax/libs/jquery/1.7.1/jquery.min.JS"></script</a>>
</head>
<script>
$(document).ready(function(){
var c=document.getElementById("drawbox");
var draw=c.getContext("2d"); //獲取2d內容的引用,調用繪圖API</p><p>//指定漸變區塊
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>
效果圖: