Open goldEli opened 4 years ago
Canvas是h5的画布工具,可以通过js画任何你想画的东西。丰富浏览器图形元素
<canvas id="canvas" width="600" height="400"></canvas>
<script>
// function draw(){
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext("2d");
ctx.fillStyle = 'red';
ctx.arc(300,200,100,0,Math.PI*2)
ctx.fill();
// }
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>canvas实现圆</title>
</head>
<body>
<canvas id="vas" width="300" height="300"></canvas>
<script>
var canvas = document.getElementById("vas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "red";
ctx.arc(100, 100, 100, 0, Math.PI * 2)
ctx.fill();
</script>
</body>
</html>
创建一个画布,通过js脚本在画布上画东西
画圆
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<canvas id="myCanvas" width="200" height="100" style="border: 1px solid #000000;"></canvas>
</body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.fillStyle="red";
ctx.arc(50,50,50,0,Math.PI * 2);
ctx.stroke();
ctx.fill();
</script>
</html>
arc(x,y,radius,start,end),
x,y确定圆心位置,radius设置半径,start起始弧度,end结束弧度