svg画loading

成品效果

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>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容

  • 转载请声明 原文链接 关注公众号获取更多资讯 这篇文章主要总结H5的一些新增的功能以及一些基础归纳,这里只是一个提...
    程序员poetry阅读 9,049评论 22 225
  • SVG 学习笔记 SVG是什么 SVG 指可伸缩矢量图形 (Scalable Vector Graphics) S...
    Penn_Xu阅读 952评论 0 1
  • 一、什么是SVG? SVG指可伸缩矢量图形(Scalable Vector Graphics); SVG用来定义用...
    清心挽风阅读 1,375评论 1 3
  • 一:什么是SVG? 对于SVG的定义如下: ①:SVG 指的是可伸缩矢量图形 (Scalable Vector G...
    GreenHand1阅读 789评论 0 1
  • 1、属性选择器:id选择器 # 通过id 来选择类名选择器 . 通过类名来选择属性选择器 ...
    Yuann阅读 1,604评论 0 7