js+canvas简单绘制圆圈的方法

运行效果截图如下:

js+canvas简单绘制圆圈的方法

具体代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>canvas画圆圈</title> <script type="text/javascript" > function drawCircle(id){ var canvas = document.getElementById(id); if(canvas ) { var context = canvas.getContext("2d"); context.fillStyle = "gray"; context.strokeStyle = "black"; context.fillRect(0, 0, 400, 400); context.beginPath(); context.arc(100, 100, 50, 0, Math.PI*2, true); context.closePath(); context.fillStyle = "green"; context.fill(); } else { return; } } window.onload = function () { drawCircle("canvas"); } </script> </head> <body> <canvas></canvas> <hr /> </body> </html>

更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript动画特效与技巧汇总》及《JavaScript运动效果与技巧汇总

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgwzyp.html