svg 线条动画

原文链接: svg 线条动画

上一篇: 按照笔画顺序写汉字

下一篇: cocos 刚体碰撞 台球游戏

https://zhuanlan.zhihu.com/p/151598924

https://www.cnblogs.com/coco1s/p/6225973.html

up-d59d1b2abf243cebe96bee6c40202e63118.gif

使用css变量, 控制线条动画

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      path {
        animation: move 3s linear forwards infinite;
        /* --main-path-len: 511px; */
      }

      @keyframes move {
        0% {
          stroke-dasharray: 0, var(--main-path-len);
        }
        100% {
          stroke-dasharray: var(--main-path-len), 0;
        }
      }
    </style>
  </head>
  <body>
    <svg width="400px" height="400px" viewBox="0 0 800 800">
      <path
        id="path"
        fill="none"
        stroke="#000"
        stroke-width="1px"
        d="M452,293c0,0,0-61,72-44c0,0-47,117,81,57
    s5-110,10-67s-51,77.979-50,33.989"
      />
    </svg>
    <script>
      const p = document.getElementsByTagName("path")[0]
      console.log(p.getTotalLength())
      const s = p.getTotalLength() + "px"
      console.log(p.style, s)
      p.style.setProperty("--main-path-len", s)
    </script>
  </body>
</html>

圆环进度条填充

up-3d901027765c26185de914a4e22d06dd4e6.gif

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .circle-load {
        position: absolute;
        width: 200px;
        height: 200px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }

      .circle-load-svg {
        stroke-dasharray: 0 570;
        animation: rot 8s linear infinite;
      }

      @keyframes rot {
        100% {
          stroke-dasharray: 570 570;
        }
      }
    </style>
  </head>
  <body>
    <svg
      width="240px"
      height="240px"
      version="1.1"
      xmlns="http://www.w3.org/2000/svg"
    >
      <circle
        cx="110"
        cy="110"
        r="90"
        stroke-width="10"
        stroke="gainsboro"
        fill="none"
      ></circle>
      <circle
        cx="110"
        cy="110"
        r="90"
        stroke-width="10"
        stroke="darkturquoise"
        fill="none"
        class="circle-load-svg"
      ></circle>
    </svg>
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值