HTML5画矩形
1、源码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5画矩形</title>
<script>
function draw(id)
{
var canvas = document.getElementById("canvas");
if(canvas == null)
{
return false;
}
var context = canvas.getContext("2d");
context.fillStyle = "#FF00000";
context.fillRect(0,0,500,600);
for(var i=0;i<10;i++)
{
context.beginPath();
context.arc(i*25,i*25,i*10,0,Math.PI*2,true);
context.closePath();
context.fillStyle = "#00FF00";
context.fill();
}
}
</script>
</head>
<body onLoad="draw('canvas')">
<canvas id="canvas" width="500px" height="600px"></canvas>
</body>
</html>
2、结果
HTML5 Canvas画矩形
本文介绍如何使用HTML5的Canvas API绘制矩形,并通过JavaScript实现动态圆形图案填充。通过设置fillStyle属性来改变填充颜色,利用fillRect方法绘制矩形,通过arc方法绘制圆形。
2101

被折叠的 条评论
为什么被折叠?



