RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 652273
Accepted
Alexandr_TT
Alexandr_TT
Asked:2020-04-11 18:17:02 +0000 UTC2020-04-11 18:17:02 +0000 UTC 2020-04-11 18:17:02 +0000 UTC

如何像“行军蚂蚁”一样制作带有边框旋转的平滑点动画

  • 772

我正在制作一个css使用齿轮齿和链条的动画,但我无法创建smooth边框旋转序列。

你可以在fiddle中看到我如何使用伪元素来创建旋转效果。这是通过在白色虚线边框和金色虚线边框之间切换来完成的,这使得它看起来像“边框在旋转”。

这是代码:

#one{
  -webkit-animation: rotateClockwiseAnimation 5s linear infinite; /* Safari 4+ */
  -moz-animation:    rotateClockwiseAnimation 5s linear infinite; /* Fx 5+ */
  -o-animation:      rotateClockwiseAnimation 5s linear infinite; /* Opera 12+ */
  animation:         rotateClockwiseAnimation 5s linear infinite; /* IE 10+, Fx 29+ */

}
#two{
  -webkit-animation: rotateAntiClockwiseAnimation 5s linear infinite; /* Safari 4+ */
  -moz-animation:    rotateAntiClockwiseAnimation 5s linear infinite; /* Fx 5+ */
  -o-animation:      rotateAntiClockwiseAnimation 5s linear infinite; /* Opera 12+ */
  animation:         rotateAntiClockwiseAnimation 5s linear infinite; /* IE 10+, Fx 29+ */

 position:absolute;
    top:30px;
    left:42px;
    width:80px;
}

@-webkit-keyframes rotateClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@-moz-keyframes rotateClockwiseAnimation{
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@-o-keyframes rotateClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes rotateClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@-webkit-keyframes rotateAntiClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}
@-moz-keyframes rotateAntiClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}
@-o-keyframes rotateAntiClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}
@keyframes rotateAntiClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}

/******************************************************************************/

.chain{
    height:70px;
    width:80%;
    border:5px dashed gold;
    border-radius:30px;
    position:absolute;
    top:30px;
    left:40px;
          -webkit-animation: switchGoldBlackBorder 0.8s infinite; /* Safari 4+ */
  -moz-animation:    switchGoldBlackBorder 0.8s infinite; /* Fx 5+ */
  -o-animation:      switchGoldBlackBorder 0.8s infinite; /* Opera 12+ */
  animation:         switchGoldBlackBorder 0.8s infinite; /* IE 10+, Fx 29+ */
}


@-webkit-keyframes switchBlackGoldBorder {
    0%   { border: 5px dashed transparent; }
    49%   { border: 5px dashed transparent; }
    50%   { border: 5px dashed gold; }
    100%   { border: 5px dashed gold; }
}
@-moz-keyframes switchBlackGoldBorder{
    0%   { border: 5px dashed transparent; }
    49%   { border: 5px dashed transparent; }
    50%   { border: 5px dashed gold; }
    100%   { border: 5px dashed gold; }
}
@-o-keyframes switchBlackGoldBorder {
    0%   { border: 5px dashed transparent; }
    49%   { border: 5px dashed transparent; }
    50%   { border: 5px dashed gold; }
    100%   { border: 5px dashed gold; }
}
@keyframes switchBlackGoldBorder {  
    0%   { border: 5px dashed transparent; }
    49%   { border: 5px dashed transparent; }
    50%   { border: 5px dashed gold; }
    100%   { border: 5px dashed gold; }
}



.chain:after{
    content:"";
    position:absolute;
    height:70px;
    border-radius:30px;
    width:100%;
    top:-5px;
    left:-5px;
    border:5px solid gold;
    z-index:-1;
          -webkit-animation: switchBlackGoldBorder 0.8s infinite; /* Safari 4+ */
  -moz-animation:    switchBlackGoldBorder 0.8s infinite; /* Fx 5+ */
  -o-animation:      switchBlackGoldBorder 0.8s infinite; /* Opera 12+ */
  animation:         switchBlackGoldBorder 0.8s infinite; /* IE 10+, Fx 29+ */
}

@-webkit-keyframes switchGoldBlackBorder {
  0%   { border: 5px solid gold; }
    49%   { border: 5px solid gold; }
    50%   { border: 5px solid white; }
    100%   { border: 5px solid white; }
}
@-moz-keyframes switchGoldBlackBorder{
  0%   { border: 5px solid gold; }
    49%   { border: 5px solid gold; }
    50%   { border: 5px solid white; }
    100%   { border: 5px solid white; }
}
@-o-keyframes switchGoldBlackBorder {
  0%   { border: 5px solid gold; }
    49%   { border: 5px solid gold; }
    50%   { border: 5px solid white; }
    100%   { border: 5px solid white; }
}
@keyframes switchGoldBlackBorder {  
    0%   { border: 5px solid gold; }
    49%   { border: 5px solid gold; }
    50%   { border: 5px solid white; }
    100%   { border: 5px solid white; }
}
<svg id="one" style="width:50px" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100">
    <defs>
        <circle id="c" cx="50" cy="50" r="30" stroke="#808080" fill="none" stroke-width="25"/>
        <path id="d" stroke="#808080" stroke-width="16" d="M50 0, V15 M50 100, V85 M0 50, H15 M100 50, H85"/>
    </defs>    
    <use xlink:href="#c"/>
    <use xlink:href="#d"/>
    <use xlink:href="#d" transform="rotate(45, 50, 50)"/>
</svg>

<svg id="two" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100">
    <use xlink:href="#one"/>    
</svg>
<div class="chain"></div>

所以在底部snippet你可以看到我是如何使用创建旋转链效果的keyframes。

我一般想得到什么?

想一想传送带的横截面以及传送带末端的齿轮如何啮合传送带。我正在尝试重现这一点。
也就是说,虚线带的空心应该在齿轮齿上并拉动它。

#one{
  -webkit-animation: rotateClockwiseAnimation 5s linear infinite; /* Safari 4+ */
  -moz-animation:    rotateClockwiseAnimation 5s linear infinite; /* Fx 5+ */
  -o-animation:      rotateClockwiseAnimation 5s linear infinite; /* Opera 12+ */
  animation:         rotateClockwiseAnimation 5s linear infinite; /* IE 10+, Fx 29+ */
border:5px dashed gold;
  border-radius:50%;
}

@-webkit-keyframes rotateClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@-moz-keyframes rotateClockwiseAnimation{
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@-o-keyframes rotateClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes rotateClockwiseAnimation {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
<svg id="one" style="width:50px" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100">
    <defs>
        <circle id="c" cx="50" cy="50" r="30" stroke="#808080" fill="none" stroke-width="25"/>
        <path id="d" stroke="#808080" stroke-width="16" d="M50 0, V15 M50 100, V85 M0 50, H15 M100 50, H85"/>
    </defs>    
    <use xlink:href="#c"/>
    <use xlink:href="#d"/>
    <use xlink:href="#d" transform="rotate(45, 50, 50)"/>
</svg>

但是在齿轮齿之间加上金色的破折号,整个机制将占据屏幕宽度的 80%(如果这有意义的话)。

最终我想创建这样的图像:

在此处输入图像描述

问题翻译:How to make a smooth dashed border rotation animation like 'marching ants' @jbutler483

css
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2020-04-11T18:17:02Z2020-04-11T18:17:02Z

    链条和齿轮的动画:

    完全重写了代码(CSS和HTML),现在是:

    • 简而言之(尤其是 CSS)
    • 更轻松
    • 机制的外观变得更加逼真:修复了链条和齿轮之间的同步问题,并在右侧添加了缺失的齿轮,因为您的链条似乎漂浮在空中:

    svg{width:100%;}
    #chain_st{
      -webkit-animation: dash 1s infinite linear;
      -moz-animation: dash 1s infinite linear;
      -o-animation: dash 1s infinite linear;
      animation: dash 1s infinite linear;
    }
    @-webkit-keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    @-moz-keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    @-o-keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    @keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    <svg id="one" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 30">
      <defs>
        <circle id="c" cx="20" cy="20" r="4" stroke="#808080" fill="none" stroke-width="4"/>
        <path id="d" stroke="#808080" stroke-width="2" d="M20 13 V16 M27 20 H24 M20 27 V24 M13 20 H16"/>
        <g id="cog">
          <use xlink:href="#c"/>
          <use xlink:href="#d"/>
          <use xlink:href="#d" transform="rotate(45 20 20)"/>
        </g>
      </defs>
      <g transform="translate(0,-7), scale(0.8), rotate(22.5 8 8)">
        <use xlink:href="#cog">
          <animateTransform attributeType="xml"
                        attributeName="transform"
                        type="rotate"
                        from="-22.5 20 20"
                        to="337.5 20 20"
                        dur="8s"
                        repeatCount="indefinite"/>
        </use>
      </g>
      <path id="chain_st" stroke-width="1" stroke="#000" fill="transparent" stroke-dasharray="2.6 2.45" d="M21.3 13.5 H20 C11.4 13.5 11.4 26.5 20 26.5 H80 C89 26.5 89 13.5 80.8 13.5z" />
      <use class="rot" xlink:href="#cog">
        <animateTransform attributeType="xml"
                        attributeName="transform"
                        type="rotate"
                        from="22.5 20 20"
                        to="-337.5 20 20"
                        dur="8s"
                        repeatCount="indefinite"/>
      </use>
      <g transform="translate(60.3 0)">
        <use class="" xlink:href="#cog">
          <animateTransform attributeType="xml"
                        attributeName="transform"
                        type="rotate"
                        from="22.5 20 20"
                        to="-337.5 20 20"
                        dur="8s"
                        repeatCount="indefinite"/>
        </use>
      </g>
    </svg>  

    该方法与动画化齿轮的旋转角度和链条的移动行程相同。
    我调整了两个动画之间的时间,让它看起来像是齿轮在拉动链条。

    浏览器支持:

    由于IE 它不支持元素,我还用 snap.svgsvg animate库制作了这个版本的动画,它也支持更多(通过crossbrowsertesting测试)。 IE9IE9

    带 IE 支持的 DEMO

    var cont   = new Snap('#svg'),
        chain  = cont.select('#chain'),
        cogAcw = cont.select('#cog_acw'),
        cogCw  = cont.select('#cog_cw'),
        speed  = 500;  // Lower this number to make the animation faster
    
    function infChain(el) {
        var len = el.getTotalLength();
        el.attr({"stroke-dasharray": len/62,"stroke-dashoffset": 0});
        el.animate({"stroke-dashoffset": -len/31}, speed, mina.linear, infChain.bind(null, el));
    }
    function rotateAcw(el) {
        el.transform('r22.5,20,20');
        el.animate({ transform: 'r-22.5,20,20' }, speed, mina.linear, rotateAcw.bind( null, el));
    }
    function rotateCw(el) {
        el.transform('r0,20,20');
        el.animate({ transform: 'r45,20,20' }, speed, mina.linear, rotateCw.bind( null, el));
    }
    infChain(chain);
    rotateAcw(cogAcw);
    rotateCw(cogCw); 
    svg {
        width:100%;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg.js"></script>
    <svg id="svg" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 30">
        <defs>
            <circle id="c" cx="20" cy="20" r="4" stroke="#808080" fill="none" stroke-width="4" />
            <path id="d" stroke="#808080" stroke-width="2" d="M20 13 V16 M27 20 H24 M20 27 V24 M13 20 H16" />
            <g id="cog_acw">
                <use xlink:href="#c" /><use xlink:href="#d" />
                <use xlink:href="#d" transform="rotate(45 20 20)" />
            </g>  
            <g id="cog_cw">
                <use xlink:href="#c" /><use xlink:href="#d" />
                <use xlink:href="#d" transform="rotate(45 20 20)" />
            </g>  
        </defs>
        <path id="chain" stroke-width="1" stroke="#000" fill="transparent" 
        d="M21.3 13.5 H20 C11.4 13.5 11.4 26.5 20 26.5 H80 C89.4 26.5 89.4 13.5 80.8 13.5z" />
        <use  xlink:href="#cog_acw" />
        <use  transform="translate(60.5 0), rotate(19,20,20)" xlink:href="#cog_acw" />
        <use  transform="translate(-4.5 -4.5),scale(.8), rotate(0,20,20)" xlink:href="#cog_cw" />    
    </svg>   

    对于现代浏览器

    svg{width:100%;}
    #chain_st{
      -webkit-animation: dash 1s infinite linear;
      -moz-animation: dash 1s infinite linear;
      -o-animation: dash 1s infinite linear;
      animation: dash 1s infinite linear;
    }
    @-webkit-keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    @-moz-keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    @-o-keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    @keyframes dash {
      to { stroke-dashoffset: -5; }
    }
    <svg id="one" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 30">
      <defs>
        <circle id="c" cx="20" cy="20" r="4" stroke="#808080" fill="none" stroke-width="4"/>
        <path id="d" stroke="#808080" stroke-width="2" d="M20 13 V16 M27 20 H24 M20 27 V24 M13 20 H16"/>
        <g id="cog">
          <use xlink:href="#c"/>
          <use xlink:href="#d"/>
          <use xlink:href="#d" transform="rotate(45 20 20)"/>
        </g>
      </defs>
      <g transform="translate(0,-7), scale(0.8), rotate(22.5 8 8)">
        <use xlink:href="#cog">
          <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="-22.5 20 20" to="337.5 20 20" dur="8s" repeatCount="indefinite"/>
        </use>
      </g>
      <path id="chain_st" stroke-width="1" stroke="#000" fill="transparent" stroke-dasharray="2.6 2.45" d="M21.3 13.5 H20 C11.4 13.5 11.4 26.5 20 26.5 H80 C89 26.5 89 13.5 80.8 13.5z" />
      <use class="rot" xlink:href="#cog">
        <animateTransform attributeType="xml" attributeName="transform" type="rotate"from="22.5 20 20" to="-337.5 20 20" dur="8s" repeatCount="indefinite"/>
      </use>
      <g transform="translate(60.3 0)">
        <use class="" xlink:href="#cog">
          <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="22.5 20 20" to="-337.5 20 20" dur="8s" repeatCount="indefinite"/>
        </use>
      </g>
    </svg>

    问题作者代码的建议:

    您可以使用另一个并使用 为属性设置svg dashed path动画。 dash-offsetkeyframe animation

    这可以而且应该针对“真实世界”使用进行简化/定制:

    • 所有元素都可以放在一个标签中<svg>(这将使事情变得更容易,齿轮 + 链元素可以一起调整大小)
    • 链条和齿轮之间的正时不完美,需要调整链条速度/尺寸。

    笔记。译者

    在下面的代码片段中,回答者更正了主题问题中的原始代码

    #one {
      -webkit-animation: rotateClockwiseAnimation 5s linear infinite;
      /* Safari 4+ */
      -moz-animation: rotateClockwiseAnimation 5s linear infinite;
      /* Fx 5+ */
      -o-animation: rotateClockwiseAnimation 5s linear infinite;
      /* Opera 12+ */
      animation: rotateClockwiseAnimation 5s linear infinite;
      /* IE 10+, Fx 29+ */
    }
    #two {
      -webkit-animation: rotateAntiClockwiseAnimation 5s linear infinite;
      /* Safari 4+ */
      -moz-animation: rotateAntiClockwiseAnimation 5s linear infinite;
      /* Fx 5+ */
      -o-animation: rotateAntiClockwiseAnimation 5s linear infinite;
      /* Opera 12+ */
      animation: rotateAntiClockwiseAnimation 5s linear infinite;
      /* IE 10+, Fx 29+ */
      position: absolute;
      top: 30px;
      left: 42px;
      width: 80px;
    }
    @-webkit-keyframes rotateClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }
    @-moz-keyframes rotateClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }
    @-o-keyframes rotateClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }
    @keyframes rotateClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }
    @-webkit-keyframes rotateAntiClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(-360deg);
      }
    }
    @-moz-keyframes rotateAntiClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(-360deg);
      }
    }
    @-o-keyframes rotateAntiClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(-360deg);
      }
    }
    @keyframes rotateAntiClockwiseAnimation {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(-360deg);
      }
    }
    /******************************************************************************/
    
    #chain {
      width: 650px;
      position: absolute;
      top: 24px;
      left: 35px;
    }
    .chain_st {
      stroke-dasharray: 1.5;
      stroke-dashoffset: 10;
      -webkit-animation: dash 18s infinite linear;
      -moz-animation: dash 18s infinite linear;
      -o-animation: dash 18s infinite linear;
      animation: dash 18s infinite linear;
    }
    @-webkit-keyframes dash {
      to {
        stroke-dashoffset: 100;
      }
    }
    @-moz-keyframes dash {
      to {
        stroke-dashoffset: 100;
      }
    }
    @-o-keyframes dash {
      to {
        stroke-dashoffset: 100;
      }
    }
    keyframes dash {
      to {
        stroke-dashoffset: 100;
      }
    }
    <svg id="one" style="width:50px" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100">
      <defs>
        <circle id="c" cx="50" cy="50" r="30" stroke="#808080" fill="none" stroke-width="25" />
        <path id="d" stroke="#808080" stroke-width="16" d="M50 0, V15 M50 100, V85 M0 50, H15 M100 50, H85" />
      </defs>
      <use xlink:href="#c" />
      <use xlink:href="#d" />
      <use xlink:href="#d" transform="rotate(45, 50, 50)" />
    </svg>
    
    <svg id="two" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100">
      <use xlink:href="#one" />
    </svg>
    <svg id="chain" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 70 10">
      <path class="chain_st" stroke-width="0.5" stroke="#000" fill="transparent" d="M60 1 Q65 1 65 5 Q65 9 60 9 H6 Q1 9 1 5 Q1 1 6 1z" />
    </svg>

    答案翻译:如何制作平滑的虚线边框旋转动画,如“行进的蚂蚁”@web-tiki

    • 7
  2. Alexandr_TT
    2020-04-11T22:28:12Z2020-04-11T22:28:12Z

    笔记。

    我重新制作了所有动画,box-shadow因为使用情况dashed borders在所有浏览器中都没有一致的输出。

    Работает

    .. и работает кроссбраузерно.
    FF 5+, GC 4+, IE9+, Safari 4+, Opera 12.1+

    Вы можете попробовать это с помощью box-shadow:

    • Чтобы сделать зубья шестеренок, используйте box-shadow с отрицательным spread radius. Размер моей шестеренки был, например: 50px , поэтому, чтобы использовать box-shadow с d = 8px, я установил -46px, как spread radius.
    • Я разместил зубья шестеренки, используя координаты geo, и сделал только 8 зубьев для упрощения.
    • Теперь для прямого участка конвейера, нам нужно узнать расстояние между зубьями . Мы получаем это следующим образом:
    • 2*pi*(r шестеренки) / кол. зубьев = (pi * r) / 4
      результат = (55 * 3.1415) / 4 = 43 (приблизительно)

      Я взял радиус 55, потому что зубья имеют радиус 4px и находятся на расстоянии 1px от окружности шестерни.
      прим. переводчика: 55 - это диаметр.
    • 要对齐传送带的上下直线段,需要将它们移动到任意倍数的距离。对于我的齿轮,我将它们设置为43px.

    框架

    小提琴

       body {
    background: rgba(25,80,175, 0.4);
    }
    .rect {
    height: 116px;
    width: 401px;
    border-radius: 58px;
    position: relative;
    overflow: hidden;
    }
    
    .rect:before, .rect:after {
    content: '';
    position: absolute;
    left: 46px; /*50-half width*/
    height: 8px;
    width: 8px;
    border-radius: 50%;
    background: transparent;
    box-shadow: 43px 0 0 0 white, 86px 0 0 0 white, 129px 0 0 0 white, 172px 0 0 0 white, 215px 0 0 0 white, 258px 0 0 0 white, 301px 0 0 0 white;
    -webkit-animation: apple 0.3s linear infinite;
    -moz-animation: apple 0.3s linear infinite;
    animation: apple 0.3s linear infinite;
    }
    .rect:before {
    top: 0px;
    }
    .rect:after {
    bottom: 0px;
    -webkit-animation-direction: reverse;
    -moz-animation-direction: reverse;
    animation-direction: reverse;
    }
    @-webkit-keyframes apple {
    0% {-webkit-transform: translatex(0px);}
    100% {-webkit-transform: translateX(-43px);}
    }
    @-moz-keyframes apple {
    0% {-moz-transform: translatex(0px);}
    100% {-moz-transform: translateX(-43px);}
    }
    @keyframes apple {
    0% {transform: translatex(0px);}
    100% {transform: translateX(-43px);}
    }
    .left, .right {
    content: '';
    position: relative;
    height: 100px;
    width: 100px;
    border-radius: 50px;
    background-color: #222;
    box-shadow: 0 55px 0 -46px white, 55px 0 0 -46px white, 0 -55px 0 -46px white, -55px 0 0 -46px white,
        39px 39px 0 -46px white, -39px -39px 0 -46px white, 39px -39px 0 -46px white, -39px 39px 0 -46px white;
    -webkit-animation: mango 2.4s linear infinite;
    -moz-animation: mango 2.4s linear infinite;
    animation: mango 2.4s linear infinite;
    }
    .left {
    top: -108px;
    left: 0px;
    }
    .right {
    top: -208px;
    left: 301px;
    }
    @-webkit-keyframes mango {
    0% {-webkit-transform: rotate(0deg);}
    100% {-webkit-transform: rotate(-360deg);}
    }
    @-moz-keyframes mango {
    0% {-moz-transform: rotate(0deg);}
    100% {-moz-transform: rotate(-360deg);}
    }
    @keyframes mango {
    0% {transform: rotate(0deg);}
    100% {transform: rotate(-360deg);}
    }
    <div class="rect"></div>
    <div class="left"></div>
    <div class="right"></div>

    最终版本

    ...带齿轮。连锁dotted dashed吧!

    小提琴

    body {
        background-color: white;
    }
    .rect {
        height: 120px;
        width: 401px;
        border-radius: 58px;
        position: relative;
    }
    
    .rect:before, .rect:after {
        content: '';
        position: absolute;
        left: 40px; /*50-half width*/
        height: 10px;
        width: 20px;
        background: transparent;
        box-shadow: 43px 0 0 0 gold, 86px 0 0 0 gold, 129px 0 0 0 gold, 172px 0 0 0 gold, 215px 0 0 0 gold, 258px 0 0 0 gold, 301px 0 0 0 gold, 344px 0 0 0 gold; /*keep adding 43 to x-axis*/
        -webkit-animation: apple 0.6s linear infinite;
        -moz-animation: apple 0.6s linear infinite;
        animation: apple 0.6s linear infinite;
        overflow: hidden;
    }
    .rect:before {
        top: 0px;
    }
    .rect:after {
        bottom: 0px;
        -webkit-animation-direction: reverse;
        -moz-animation-direction: reverse;
        animation-direction: reverse;
    }
    @-webkit-keyframes apple {
        0% {-webkit-transform: translatex(0px);}
        100% {-webkit-transform: translateX(-43px);}
    }
    @-moz-keyframes apple {
        0% {-moz-transform: translatex(0px);}
        100% {-moz-transform: translateX(-43px);}
    }
    @keyframes apple {
        0% {transform: translatex(0px);}
        100% {transform: translateX(-43px);}
    }
    .left, .right {
        content: '';
        position: relative;
        height: 100px;
        width: 100px;
        border-radius: 50px;
        -webkit-animation: mango 4.8s linear infinite;
        -moz-animation: mango 4.8s linear infinite;
        animation: mango 4.8s linear infinite;
    }
    .left {
        top: -110px;
        left: 0px;
    }
    .right {
        top: -210px;
        left: 344px;
    }
    .left:before, .left:after, .right:before, .right:after {
        height: 20px;
        width: 20px;
        content: '';
        position: absolute;
        background-color: gold;
    }
    .left:before, .right:before {
        box-shadow: 50px 50px 0 0 gold, -50px 50px 0 0 gold, 0 100px 0 0 gold;
        top: -10px;
        left: 40px;
    }
    .left:after, .right:after {
        transform: rotate(45deg);
        top: 5px;
        left: 76px;
        box-shadow: 0px 100px 0 0 gold, 50px 50px 0 0 gold, -50px 50px 0 0 gold;
    }
    @-webkit-keyframes mango {
        0% {-webkit-transform: rotate(0deg);}
        100% {-webkit-transform: rotate(-360deg);}
    }
    @-moz-keyframes mango {
        0% {-moz-transform: rotate(0deg);}
        100% {-moz-transform: rotate(-360deg);}
    }
    @keyframes mango {
        0% {transform: rotate(0deg);}
        100% {transform: rotate(-360deg);}
    }
    .cover {
        height: 104px;
        width: 446px;
        border-radius: 50px;
        position: relative;
        background: rgba(255,255,255,1);
        top: -312px;
        left; -2px;
        
    }
    .gear, .gear2 {
        height: 100px;
        width: 100px;
        background: dimgray;
        border-radius: 50%;
        position: relative;
        -webkit-animation: gear 4.8s linear infinite;
        -moz-animation: gear 4.8s linear infinite;
        animation: gear 4.8s linear infinite;
    }
    .gear {
        top: -414px;
      
    }
    .gear2 {
        top: -514px;
        left: 345px;
    }
    .gear:before, .gear:after, .gear2:before, .gear2:after {
        height: 20px;
        width: 20px;
        content: '';
        position: absolute;
        background-color: dimgray;
        
    }
    .gear:before, .gear2:before {
        box-shadow: 50px 50px 0 0 dimgray, -50px 50px 0 0 dimgray, 0 100px 0 0 dimgray;
        top: -10px;
        left: 40px;
    }
    .gear:after, .gear2:after {
        transform: rotate(45deg);
        top: 5px;
        left: 76px;
        box-shadow: 0px 100px 0 0 dimgray, 50px 50px 0 0 dimgray, -50px 50px 0 0 dimgray;
    }
    @-webkit-keyframes gear {
        0% {-webkit-transform: rotate(22.5deg);}
        100% {-webkit-transform: rotate(-337.5deg);}
    }
    @-moz-keyframes gear {
        0% {-moz-transform: rotate(22.5deg);}
        100% {-moz-transform: rotate(-337.5deg);}
    }
    @keyframes gear {
        0% {transform: rotate(22.5deg);}
        100% {transform: rotate(-337.5deg);}
    }
    <div class="rect"></div>
    <div class="left"></div>
    <div class="right"></div>
    <div class="cover"></div>
    <div class="gear"></div>
    <div class="gear2"></div>

    最终版本(圆形齿轮齿)

    .rect {
        height: 120px;
        width: 401px;
        border-radius: 58px;
        position: relative;
    }
    .rect:before, .rect:after {
        content: '';
        position: absolute;
        left: 40px; /*50-half width*/
        height: 10px;
        width: 20px;
        box-shadow: 43px 0 0 0 gold, 86px 0 0 0 gold, 129px 0 0 0 gold, 172px 0 0 0 gold, 215px 0 0 0 gold, 258px 0 0 0 gold, 301px 0 0 0 gold, 344px 0 0 0 gold; /*keep adding 43 to x-axis*/
        -webkit-animation: translate 0.6s linear infinite;
        -moz-animation: translate 0.6s linear infinite;
        animation: translate 0.6s linear infinite;
        overflow: hidden;
    }
    .rect:before {top: 0px;}
    .rect:after {
        bottom: 0px;
        -webkit-animation-direction: reverse;
        -moz-animation-direction: reverse;
        animation-direction: reverse;
    }
    @-webkit-keyframes translate {
        0% {-webkit-transform: translatex(0px);}
        100% {-webkit-transform: translateX(-43px);}
    }
    @-moz-keyframes translate {
        0% {-moz-transform: translatex(0px);}
        100% {-moz-transform: translateX(-43px);}
    }
    @keyframes translate {
        0% {transform: translatex(0px);}
        100% {transform: translateX(-43px);}
    }
    .left, .right {
        position: relative;
        height: 100px;
        width: 100px;
        border-radius: 50px;
        -webkit-animation: rotate 4.8s linear infinite;
        -moz-animation: rotate 4.8s linear infinite;
        animation: rotate 4.8s linear infinite;
    }
    .left {
        top: -110px; left: 0px;
    }
    .right {
        top: -210px; left: 344px;
    }
    .left:before, .left:after, .right:before, .right:after {
        height: 20px;
        width: 20px;
        content: '';
        position: absolute;
        background: gold;
    }
    .left:before, .right:before {
        box-shadow: 50px 50px 0 0 gold, -50px 50px 0 0 gold, 0 100px 0 0 gold;
        top: -10px;
        left: 40px;
    }
    .left:after, .right:after {
        transform: rotate(45deg);
        top: 5px;
        left: 76px;
        box-shadow: 0px 100px 0 0 gold, 50px 50px 0 0 gold, -50px 50px 0 0 gold;
    }
    @-webkit-keyframes rotate {
        0% {-webkit-transform: rotate(0deg);}
        100% {-webkit-transform: rotate(-360deg);}
    }
    @-moz-keyframes rotate {
        0% {-moz-transform: rotate(0deg);}
        100% {-moz-transform: rotate(-360deg);}
    }
    @keyframes rotate {
        0% {transform: rotate(0deg);}
        100% {transform: rotate(-360deg);}
    }
    .cover {
        height: 104px;
        width: 446px;
        border-radius: 50px;
        position: relative;
        background: rgba(255,255,255,1);
        top: -312px;
        left; -2px;
    }
    .gear, .gear2, .gear3 {
        height: 100px;
        width: 100px;
        background: transparent;
        box-shadow: inset 0 0 0px 35px dimgray, inset 0 0 0px 40px #444;
        border-radius: 50%;
        position: relative;
        -webkit-animation: rotate 4.8s linear infinite;
        -moz-animation: rotate 4.8s linear infinite;
        animation: rotate 4.8s linear infinite;
        -webkit-animation-delay: 0.3s;
        -moz-animation-delay: 0.3s;
        animation-delay: 0.3s;
    }
    .gear {top: -414px;}
    .gear2 {top: -514px; left: 345px;}
    .gear:before, .gear:after, .gear2:before, .gear2:after,  .gear3:before, .gear3:after {
        height: 20px;
        width: 20px;
        content: '';
        border-radius: 20%;
        position: absolute;
        background: dimgray;
    }
    .gear:before, .gear2:before, .gear3:before {
        box-shadow: 50px 50px 0 0 dimgray, -50px 50px 0 0 dimgray, 0 100px 0 0 dimgray;
        top: -10px; left: 40px;
    }
    .gear:after, .gear2:after, .gear3:after {
        transform: rotate(45deg);
        top: 5px; left: 76px;
        box-shadow: 0px 100px 0 0 dimgray, 50px 50px 0 0 dimgray, -50px 50px 0 0 dimgray;
    }
    .gear3 {
        -webkit-animation-direction: reverse;
        -moz-animation-direction: reverse;
        animation-direction: reverse;
        top: -504px;
        -webkit-animation-delay: 0s;
        -moz-animation-delay: 0s;
        animation-delay: 0s;
    }
    <div class="rect"></div>
    <div class="left"></div>
    <div class="right"></div>
    <div class="cover"></div>
    <div class="gear"></div>
    <div class="gear2"></div>
    <div class="gear3"></div>

    小提琴 - 圆齿

    注意。要提高动画速度,只需按比例减少每个元素的动画持续时间即可。

    小提琴(快速)

    答案翻译:如何制作平滑的虚线边框旋转动画,如“行军中的蚂蚁”@The Pragmatick

    • 6

相关问题

Sidebar

Stats

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

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +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
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +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