管道流动效果---svg

最近有些迷恋上了动画,感觉好吊啊。正好碰到需求,需求是这样:类似流水线,要看到流动的方向,例如从左到右。最终使用svg 的polyline多线段绘制方法,并配合linearGradient设置渐变,实现。

 

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .border-view {
        display: flex;
        justify-content: center;
        margin-top: 40px;
      }
      .container {
        position: relative;
        height: 200px;
        width: 200px;
        background-color: beige;
      }
      svg {
        position: absolute;
      }

      polyline {
        animation: dash 5000s linear infinite;
      }

      @keyframes dash {
        to {
          stroke-dashoffset: -200000;
        }
      }
    </style>
  </head>
  <body>
    <div class="border-view">
      <div class="container">
        <svg width="200" height="200">
          <linearGradient id="linear" x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="0%" stop-color="green" />
            <stop offset="100%" stop-color="red" />
          </linearGradient>
          <polyline
            points="0,10 100,10 100,80 190,80 190,200"
            style="
              fill: white;
              stroke-dasharray: 0, 20;
              stroke: url(#linear);
              stroke-linecap: round;
              stroke-width: 10;
            "
          />

         
        </svg>
      </div>
    </div>
  </body>
</html>

后来再次基础上 实现健康宝页面小球动画。可是掉了好多头发终于感觉可行了。只能说svg好猛。

 

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .border-view {
        display: flex;
        justify-content: center;
        margin-top: 40px;
      }
      .container {
        position: relative;
        height: 200px;
        width: 200px;
        background-color: beige;
      }
      svg {
        position: absolute;
      }

      polyline {
        animation: dash 5000s linear infinite;
      }

      @keyframes dash {
        to {
          stroke-dashoffset: -200000;
        }
      }
    </style>
  </head>
  <body>
    <div class="border-view">
      <div class="container">
        <svg width="200" height="200">
          <linearGradient id="linear" x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="0%" stop-color="green" />
            <stop offset="100%" stop-color="red" />
          </linearGradient>

          <rect
            width="90%"
            height="90%"
            stroke-width="8"
            x="10"
            y="10"
            fill="none"
            stroke="url(#linear)"
            stroke-dasharray="0,20"
            stroke-linecap="round"
          ></rect>
        </svg>
      </div>
    </div>
  </body>
</html>

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

成序猿@

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值