HLJ 发布于
2018-08-20 12:49:52

HTML5 Canvas shadowColor,shadowBlur,shadowOffsetX和shadowOffsetY属性设置图形阴影效果

要使用HTML5 Canvas添加阴影,我们可以使用画布上下文的shadowColor,shadowBlur,shadowOffsetX和shadowOffsetY属性。
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');

      context.rect(188, 40, 200, 100);
      context.fillStyle = 'red';
      context.shadowColor = '#999';
      context.shadowBlur = 20;
      context.shadowOffsetX = 15;
      context.shadowOffsetY = 15;
      context.fill();
    </script>
  </body>
</html>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-20/168.html
最后生成于 2023-06-18 18:38:08
此内容有帮助 ?
0