<!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內(nèi)容的引用,調(diào)用繪圖API</p>
<p>//指定漸變區(qū)塊
var grd=draw.createLinearGradient(50,50,200,50); //坐標(biāo),長寬
grd.addColorStop(0,"black"); //起點顏色
grd.addColorStop(1,"green"); //終點顏色</p>
<p>draw.fillStyle=grd; //設(shè)為填充樣式
draw.fillRect(50,50,200,50); //填充進(jìn)矩形內(nèi)
})
</script>
</body>
<canvas id="drawbox" width="500" height="500"></canvas>
</body>
</html>
效果圖: