html5可以畫很多種形狀,下面是畫矩形代碼分享,大家參考使用吧
代碼如下:
<!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
draw.fillStyle="#ff0000"; //方式一指定填充顏色
draw.fillRect(0,0,300,100); //坐標(biāo)和長(zhǎng)寬
draw.fillStyle="rgba(0,0,255,0.5)"; //方式二rgb+透明度
draw.fillRect(400,0,100,100); //坐標(biāo)和長(zhǎng)寬
})
</script>
</body>
<canvas id="drawbox" width="500" height="500"></canvas>
</body>
</html>
效果圖: