RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 939762
Accepted
Monkey Mutant
Monkey Mutant
Asked:2020-02-02 07:44:34 +0000 UTC2020-02-02 07:44:34 +0000 UTC 2020-02-02 07:44:34 +0000 UTC

如何为类似形状的绘图设置动画?

  • 772

我在 illustrator 中得到了这样的文字

由于 ruSO 片段没有跳过字符数,所以我将 SVG 放入 codepen

_https://codepen.io/topicstarter/pen/YBVWKx

如何制作绘图动画?

css
  • 3 3 个回答
  • 10 Views

3 个回答

  • Voted
  1. Alexandr_TT
    2020-02-02T20:23:56Z2020-02-02T20:23:56Z

    stroke-dashoffset由于形状轮廓具有双线,因此无法根据属性更改制作动画。它们在下图中用箭头表示。要为路径设置动画,有两个主要要求:路径必须是单一的并且不能中断。

    在此处输入图像描述

    请看下面一个类似的动画示例,但它的实现原理不同:改变圆心的半径r和位置cx

    body, html {
      padding: 0;
      margin: 0;
      background: teal;
    }
    
    svg {
      display: block;
    }
    
    circle {
      animation: circles 2s alternate infinite cubic-bezier(0.5, 0, 0.5, 1);
      cy: 15;
    }
    
    circle:nth-child(4n+1) {
      fill: darkorange;
    }
    
    circle:nth-child(4n+2) {
      fill: gold;
    }
    
    circle:nth-child(4n+3) {
      fill: teal;
    }
    
    circle:nth-child(4n+4) {
      fill: tomato;
    }
    
    circle:nth-child(0) {
      animation-delay: 0s;
      cx: 61;
      r: 8.5;
    }
    
    circle:nth-child(1) {
      animation-delay: -0.15s;
      cx: 59;
      r: 9;
    }
    
    circle:nth-child(2) {
      animation-delay: -0.3s;
      cx: 57;
      r: 9.5;
    }
    
    circle:nth-child(3) {
      animation-delay: -0.45s;
      cx: 55;
      r: 10;
    }
    
    circle:nth-child(4) {
      animation-delay: -0.6s;
      cx: 53;
      r: 10.5;
    }
    
    circle:nth-child(5) {
      animation-delay: -0.75s;
      cx: 51;
      r: 11;
    }
    
    circle:nth-child(6) {
      animation-delay: -0.9s;
      cx: 49;
      r: 11.5;
    }
    
    circle:nth-child(7) {
      animation-delay: -1.05s;
      cx: 47;
      r: 12;
    }
    
    circle:nth-child(8) {
      animation-delay: -1.2s;
      cx: 45;
      r: 12.5;
    }
    
    circle:nth-child(9) {
      animation-delay: -1.35s;
      cx: 43;
      r: 13;
    }
    
    circle:nth-child(10) {
      animation-delay: -1.5s;
      cx: 41;
      r: 13.5;
    }
    
    circle:nth-child(11) {
      animation-delay: -1.65s;
      cx: 39;
      r: 14;
    }
    
    circle:nth-child(12) {
      animation-delay: -1.8s;
      cx: 37;
      r: 14.5;
    }
    
    circle:nth-child(13) {
      animation-delay: -1.95s;
      cx: 35;
      r: 15;
    }
    
    circle:nth-child(14) {
      animation-delay: -2.1s;
      cx: 33;
      r: 15.5;
    }
    
    circle:nth-child(15) {
      animation-delay: -2.25s;
      cx: 31;
      r: 16;
    }
    
    circle:nth-child(16) {
      animation-delay: -2.4s;
      cx: 29;
      r: 16.5;
    }
    
    circle:nth-child(17) {
      animation-delay: -2.55s;
      cx: 27;
      r: 17;
    }
    
    circle:nth-child(18) {
      animation-delay: -2.7s;
      cx: 25;
      r: 17.5;
    }
    
    circle:nth-child(19) {
      animation-delay: -2.85s;
      cx: 23;
      r: 18;
    }
    
    circle:nth-child(20) {
      animation-delay: -3s;
      cx: 21;
      r: 18.5;
    }
    
    circle:nth-child(21) {
      animation-delay: -3.15s;
      cx: 19;
      r: 19;
    }
    
    circle:nth-child(22) {
      animation-delay: -3.3s;
      cx: 17;
      r: 19.5;
    }
    
    circle:nth-child(23) {
      animation-delay: -3.45s;
      cx: 15;
      r: 20;
    }
    
    circle:nth-child(24) {
      animation-delay: -3.6s;
      cx: 13;
      r: 20.5;
    }
    
    circle:nth-child(25) {
      animation-delay: -3.75s;
      cx: 11;
      r: 21;
    }
    
    circle:nth-child(26) {
      animation-delay: -3.9s;
      cx: 9;
      r: 21.5;
    }
    
    circle:nth-child(27) {
      animation-delay: -4.05s;
      cx: 7;
      r: 22;
    }
    
    circle:nth-child(28) {
      animation-delay: -4.2s;
      cx: 5;
      r: 22.5;
    }
    
    circle:nth-child(29) {
      animation-delay: -4.35s;
      cx: 3;
      r: 23;
    }
    
    circle:nth-child(30) {
      animation-delay: -4.5s;
      cx: 1;
      r: 23.5;
    }
    
    circle:nth-child(31) {
      animation-delay: -4.65s;
      cx: -1;
      r: 24;
    }
    
    circle:nth-child(32) {
      animation-delay: -4.8s;
      cx: -3;
      r: 24.5;
    }
    
    circle:nth-child(33) {
      animation-delay: -4.95s;
      cx: -5;
      r: 25;
    }
    
    circle:nth-child(34) {
      animation-delay: -5.1s;
      cx: -7;
      r: 25.5;
    }
    
    circle:nth-child(35) {
      animation-delay: -5.25s;
      cx: -9;
      r: 26;
    }
    
    circle:nth-child(36) {
      animation-delay: -5.4s;
      cx: -11;
      r: 26.5;
    }
    
    circle:nth-child(37) {
      animation-delay: -5.55s;
      cx: -13;
      r: 27;
    }
    
    circle:nth-child(38) {
      animation-delay: -5.7s;
      cx: -15;
      r: 27.5;
    }
    
    circle:nth-child(39) {
      animation-delay: -5.85s;
      cx: -17;
      r: 28;
    }
    
    circle:nth-child(40) {
      animation-delay: -6s;
      cx: -19;
      r: 28.5;
    }
    
    circle:nth-child(41) {
      animation-delay: -6.15s;
      cx: -21;
      r: 29;
    }
    
    circle:nth-child(42) {
      animation-delay: -6.3s;
      cx: -23;
      r: 29.5;
    }
    
    circle:nth-child(43) {
      animation-delay: -6.45s;
      cx: -25;
      r: 30;
    }
    
    circle:nth-child(44) {
      animation-delay: -6.6s;
      cx: -27;
      r: 30.5;
    }
    
    circle:nth-child(45) {
      animation-delay: -6.75s;
      cx: -29;
      r: 31;
    }
    
    @keyframes circles {
      to {
        transform: translate(5%, 50%);
      }
    }
     <svg viewbox="0 -5 70 70">  
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
      <circle /><circle /><circle /><circle /><circle />
    </svg>
      

    来源 @web-tiki

    • 10
  2. Best Answer
    Alexandr_TT
    2020-02-03T03:19:10Z2020-02-03T03:19:10Z

    &#10677; 使用 unicode 字符⦵ 作为圆圈

    并且动画可以沿着路径绘制任何形状。

    <animate dur="40s" repeatCount="5" attributeName="startOffset" values="0%;200%;0%"/>

    .container {
       width:100%;
       height:100%;
       }
    <div class="container" >
      <svg  viewBox="0 0 600 400">
     
      <defs>
       <linearGradient id="LG" >
        <stop offset="20%" stop-color="green"/>
    	<stop offset="40%" stop-color="crimson"/>
    	<stop offset="100%" stop-color="gold"/>
      </linearGradient> 
         <linearGradient id="LG2"  x2="10%" y2="100%">
        <stop offset="70%" stop-color="dodgerblue"/>
    	<stop offset="100%" stop-color="yellowgreen"/>
      </linearGradient>
      </defs>
      <rect width="100%" height="100%" fill="url(#LG2)" />
     <path id="pathChain" d="m40 110c17.6-37.3 78.8-31.6 120-30 31.6 1.2 58.4 27.9 90 30 88.1 5.8 188.1-101.2 260-50 57.6 41.1 72.8 153.7 30 210C476.9 352.9 291.9 393.8 230 310 179.2 241.3 380.3 149.5 335.9 76.4 303.6 23.1 198.8 12.5 149 66.3 89.9 130 206.9 286 130 300 61.1 312.6 10 173.4 40 110Z" stroke="grey" fill="none"/> 
    
     <text  font-size="40"  fill="url(#LG)" >
     <textPath id="result"    xlink:href="#pathChain">
     <tspan >&#10677;  </tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan> 
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan> 
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan>
     <tspan dx="-45">&#10677;</tspan> 
    <animate  dur="30s" repeatCount="5" attributeName="startOffset" values="0%;85%;0%"/> 
    </textPath>
    </text>			
    		
    </svg>  
    </div>

    • 5
  3. Stranger in the Q
    2020-08-25T16:22:51Z2020-08-25T16:22:51Z

    你可以先隐藏所有的圆圈,然后一个一个地显示出来,结果是这样的:

    fetch('https://codepen.io/topicstarter/pen/YBVWKx.html')
      .then(r => r.text())
      .then(html => {
        document.body.innerHTML += html;
        document.querySelectorAll('ellipse').forEach((e,i) => 
          setTimeout(() => e.classList.add('visible'), i*10))
      });
    ellipse {
      opacity: 0;
      transition: 100ms;
    }
    
    ellipse.visible{
      opacity: 1;
    }
    <script>
    </script>

    • 2

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5