HLJ 发布于
2018-08-20 10:02:15

HTML5 Canvas 创建圆角

要使用HTML5 Canvas创建圆角,我们可以使用由控制点,结束点和半径定义的arcTo()方法。
html代码:
<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="578" height="200"></canvas>
    <script>
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');
      var rectWidth = 200;
      var rectHeight = 100;
      var rectX = 189;
      var rectY = 50;
      var cornerRadius = 50;

      context.beginPath();
      context.moveTo(rectX, rectY);
      context.lineTo(rectX + rectWidth - cornerRadius, rectY);
      context.arcTo(rectX + rectWidth, rectY, rectX + rectWidth, rectY + cornerRadius, cornerRadius);
      context.lineTo(rectX + rectWidth, rectY + rectHeight);
      context.lineWidth = 5;
      context.stroke();
    </script>
  </body>
</html>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-20/139.html
最后生成于 2023-06-18 18:37:41
此内容有帮助 ?
0