<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<p>canvas元素实例</p>
<canvas id="demo"></canvas>
<script>
var t=document.getElementById("demo");
var img=t.getContext("2d");
img.fillStyle="#eeeeff";
img.fillRect(0,0,400,300);
var n=0;
for(var i=0;i<10;i++)
{
img.beginPath();
img.arc(i*25,i*25,i*10,0,Math.PI*2,true);
img.closePath();
img.fillStyle="rgba(255,0,0,0.25)";
img.fill();
}
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<p>canvas元素实例</p>
<canvas id="demo"></canvas>
<script>
var t=document.getElementById("demo");
var img=t.getContext("2d");
img.fillStyle="#eeeeff";
img.fillRect(0,0,400,300);
var n=0;
for(var i=0;i<10;i++)
{
img.beginPath();
img.arc(i*25,i*25,i*10,0,Math.PI*2,true);
img.closePath();
img.fillStyle="rgba(255,0,0,0.25)";
img.fill();
}
</script>
</body>
</html>
本文介绍了一个使用HTML5 Canvas元素绘制圆形的示例。通过JavaScript获取Canvas上下文,并填充背景色,接着利用循环绘制一系列不同大小的透明度为0.25的红色圆形。
3367

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



