html5教程實現(xiàn)Photoshop漸變色效果,大家參考使用吧
代碼如下:
<!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); //坐標,長寬
grd.addColorStop(0,"black"); //起點顏色
grd.addColorStop(1,"green"); //終點顏色</p> <p>draw.fillStyle=grd; //設為填充樣式
draw.fillRect(50,50,200,50); //填充進矩形內(nèi)
})
</script>
</body>
<canvas id="drawbox" width="500" height="500"></canvas>
</body>
</html>
效果圖: