美文网首页
svg画loading

svg画loading

作者: 蝴蝶结199007 | 来源:发表于2017-11-16 18:41 被阅读26次

成品效果

loading.gif

相关代码

文本
创建一个空的svg,写入文本<text>

<text x="0" y="55" dx="68" dy="0" fill="#e1e5ed">Loading</text>
参数 描述 默认值
x 文本绘制x轴位置 0
y 文本绘制y轴位置 0
dx 每个字符相对前一个字符的偏移距离 0
dy 每个字符相对前一个字符的偏移距离 0
fill 文字的颜色 black
stroke 如果设置了stroke,字的边缘会再“描一层边”。如果设置了stroke并将fill设为none,呈现为空心字。 none

css中影响字体样式的属性同样可以作用在<text>上。

.svg text{font-size:24px;text-align:center;font-family:"Arial Black";font-bold:bold;text-shadow:0 0 7px #fff;}

text-shadow设置文字有一圈边缘阴影


其实就是一个个的圆

<circle id="1" transform="translate(135, 70) rotate(-120) translate(-135, -70) " cx="135" cy="70" r="5"></circle>

· 半径 r 等于5;
· cx 和 cy 属性定义圆点的 x 和 y 坐标。如果省略 cx 和 cy,圆的中心会被设置为 (0, 0);
· transform属性同CSS3的含义,可参考学习下:
SVG之transform
理解SVG坐标系统和变换: transform属性

接下来就是利用CSS3形成点的动画效果:
(1) 透明度的变化

@keyframes opacity {
  3% {
    fill-opacity: 1;
  }

  75% {
    fill-opacity: 0;
  }
}

(2) 颜色的变化

@keyframes colors {
  0% {
    fill: yellowgreen;
  }

  10% {
    fill: gold;
  }

  75% {
    fill: crimson;
  }
}

(3) 时间的变化
需要多个小圆点组成动画的效果,那么就需要每个点颜色、透明度变化的不在同一个时间点

circle {
  fill: dodgerblue;
  fill-opacity: 0;
  -webkit-animation: opacity 1.2s linear infinite;
  animation: opacity 1.2s linear infinite;
}

完整代码:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>loading</title>
  <style>
    svg {
      margin:0;padding:0;height: 90px;
      width: 150px;
      overflow: visible;
    }
    svg text{text-anchor: middle;font-size:24px;text-align:center;font-family:"Arial Black";font-bold:bold;text-shadow:0 0 7px #fff;}
    .g-circles {
      -webkit-transform: scale(0.9) translate(7px, 7px);
      -ms-transform: scale(0.9) translate(7px, 7px);
      transform: scale(0.9) translate(7px, 7px);
    }
    circle {
      fill: dodgerblue;
      fill-opacity: 0;
      -webkit-animation: opacity 1.2s linear infinite;
      animation: opacity 1.2s linear infinite;
    }
    circle:nth-child(12n + 1) {
      -webkit-animation-delay: -0.1s;
      animation-delay: -0.1s;
    }
    circle:nth-child(12n + 2) {
      -webkit-animation-delay: -0.2s;
      animation-delay: -0.2s;
    }
    circle:nth-child(12n + 3) {
      -webkit-animation-delay: -0.3s;
      animation-delay: -0.3s;
    }
    circle:nth-child(12n + 4) {
      -webkit-animation-delay: -0.4s;
      animation-delay: -0.4s;
    }
    circle:nth-child(12n + 5) {
      -webkit-animation-delay: -0.5s;
      animation-delay: -0.5s;
    }
    circle:nth-child(12n + 6) {
      -webkit-animation-delay: -0.6s;
      animation-delay: -0.6s;
    }
    circle:nth-child(12n + 7) {
      -webkit-animation-delay: -0.7s;
      animation-delay: -0.7s;
    }
    circle:nth-child(12n + 8) {
      -webkit-animation-delay: -0.8s;
      animation-delay: -0.8s;
    }
    circle:nth-child(12n + 9) {
      -webkit-animation-delay: -0.9s;
      animation-delay: -0.9s;
    }
    circle:nth-child(12n + 10) {
      -webkit-animation-delay: -1s;
      animation-delay: -1s;
    }
    circle:nth-child(12n + 11) {
      -webkit-animation-delay: -1.1s;
      animation-delay: -1.1s;
    }
    circle:nth-child(12n + 12) {
      -webkit-animation-delay: -1.2s;
      animation-delay: -1.2s;
    }
    .g-circles--v3 circle {
      fill-opacity: 1;
      -webkit-animation-name: opacity, colors;
      animation-name: opacity, colors;
    }
        /***透明度***/
    @-webkit-keyframes opacity {
      3% {
        fill-opacity: 1;
      }

      75% {
        fill-opacity: 0;
      }
    }

    @keyframes opacity {
      3% {
        fill-opacity: 1;
      }

      75% {
        fill-opacity: 0;
      }
    }
        /***颜色变化***/
    @-webkit-keyframes colors {
      0% {
        fill: yellowgreen;
      }

      10% {
        fill: gold;
      }

      75% {
        fill: crimson;
      }
    }
    @keyframes colors {
      0% {
        fill: yellowgreen;
      }

      10% {
        fill: gold;
      }

      75% {
        fill: crimson;
      }
    }

  </style>
</head>

<body>
    <svg viewBox="0 0 120 120" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <text x="0" y="55" dx="68" dy="0" fill="#e1e5ed">Loading</text>
      <g id="circle" class="g-circles g-circles--v3">
          <circle id="1" transform="translate(135, 70) rotate(-120) translate(-135, -70) " cx="135" cy="70" r="5"></circle>
          <circle id="2" transform="translate(120, 70) rotate(-90) translate(-120, -70) " cx="120" cy="70" r="5"></circle>
          <circle id="3" transform="translate(105, 70) rotate(-60) translate(-105, -70) " cx="105" cy="70" r="5"></circle>
          <circle id="4" transform="translate(90, 70) rotate(-30) translate(-90, -70) " cx="90" cy="70" r="5"></circle>
          <circle id="5" transform="translate(75, 70) rotate(-60) translate(-75, -70) " cx="75" cy="70" r="5"></circle>
          <circle id="6" transform="translate(60, 70) rotate(-120) translate(-60, -70) " cx="60" cy="70" r="5"></circle>
          <circle id="7" transform="translate(45, 70) rotate(-90) translate(-45, -70) " cx="45" cy="70" r="5"></circle>
          <circle id="8" transform="translate(30, 70) rotate(-60) translate(-30, -70) " cx="30" cy="70" r="5"></circle>
          <circle id="9" transform="translate(15, 70) rotate(-30) translate(-15, -70) " cx="15" cy="70" r="5"></circle>
          <circle id="10" transform="translate(0, 70) rotate(-30) translate(0, -70) " cx="0" cy="70" r="5"></circle>
      </g>
  </svg>

</body>
</html>

相关文章

  • svg画loading

    成品效果 相关代码 文本创建一个空的svg,写入文本 css中影响字体样式的属性同样可以作用在

  • svg-loading

    https://github.com/qizfeng/svg_loading

  • loading带你svg入门

    参考资料: SVG简介-前端早读 张鑫旭--一个简单的loading demo 一、svg简介 SVG 是使用 X...

  • svg loading #1

  • loading动画(svg)

    效果 组件代码 使用方式

  • svg实现简单的loading

    html css //设置实线和虚线的宽度stroke-dasharray: 50 30;//引用dash动画,动...

  • css3 小特效

    闪烁的灯、光标 摆动效果、摇摆 返回顶部小icon&css3实现小三角 svg Loading效果

  • 7.html5 笔记3 svg

    SVG 教程在线画svg path的各种指令, 就很类似 canvas的画图方式.image.pngimage.p...

  • 使用SVG实现圆环loading动画

    画圆 用SVG画一个圆先。 效果是这样的: 动画 定义一个动画并使用。 效果变成这样: 旋转 最后给动画添加上旋转...

  • 纯SVG实现的Loading动画

    ( 到这里看效果: http://www.var6.cn/work/1/22/MD的编程作品[http://www...

网友评论

      本文标题:svg画loading

      本文链接:https://www.haomeiwen.com/subject/zsplvxtx.html