HTML 画圆问题

HTML 画圆问题,第1张

<!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>

<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

<title>无标题文档</title>

</head>

<body>

<canvas id="myCanvas" width="500" height="500"></canvas>

<script type="text/javascript">

     var canvas=document.getElementById('myCanvas')

     var ctx=canvas.getContext('2d')

          //ctx.clearRect(0,0,width,height)

    ctx.beginPath()

    ctx.strokeStyle="black"

    ctx.arc(250,0,100,0,Math.PI,false)

    ctx.stroke()

    ctx.fillStyle='black'

    ctx.fill()

</script>

</body>

</html>

稍微改动一下就好了,canvas最好放js前面,而且你的代码里canvas标签没闭合,

arc里最后一个参数改为false,也就是顺时针画圆。你的是true逆时针画,画到canvas顶部外面了,当然看不到

  <div style="width:100pxheight:100pxborder:1px solid redborder-radius:50pxline-height:100pxtext-align:centercolor:red">

设计师

  </div>

要做一个圆圈,首先要做一个正方形的div,然后加上border边框,边框要用border-radius圆角,当圆角像素等于div长宽的一半时,就变成了一个圆形边框

中间的文字用line-height和text-align上下左右居中

还有那个箭头应该是图片来的,可以当背景图片插入,这个我就不写了

第一个 <canvas id="one" width="800" height="600">

第二个 <canvas id="canvas" width="800" height="600">

这就是区别!

所以第一组的 var canvas=document.getElementById('canvas')

也要相应改为 var canvas=document.getElementById('one')

这样就OK了


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/6135026.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-16
下一篇 2023-03-16

发表评论

登录后才能评论

评论列表(0条)

保存