svg fill动画在firefox中不起作用

时间:2017-06-18 08:56:11

标签: css3 svg fill svg-animate

有人知道为什么这段代码在FF中不起作用?在chrome中,一切都还可以,但不是FF。点不填充白色,只是保持未填充。

 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 129.57 26.18">
      <defs>
        <style>.cls-1{fill:none;stroke:#fff;stroke-miterlimit:10;stroke-width:2px;}</style>
      </defs>
      <title>kropeczki</title>
      <g id="Warstwa_2" data-name="Warstwa 2">
        <g id="Layer_1" data-name="Layer 1">

          <circle class="cls-1" cx="13.09" cy="13.09" r="12.09">
        <animate
        attributeName="fill" from="none" to="#fff" begin="0.7" dur=".1s" fill="freeze" repeatCount="1"/>  
          </circle>
          <circle class="cls-1" cx="64.79" cy="13.09" r="12.09">
            <animate
        attributeName="fill" from="none" to="#fff" begin="1" dur=".1s" fill="freeze" repeatCount="1"/> 
          </circle>
          <circle class="cls-1" cx="116.49" cy="13.09" r="12.09">
            <animate
        attributeName="fill" from="none" to="#fff" begin="1.3" dur=".1s" fill="freeze" repeatCount="1"/>
          </circle>
        </g>
      </g>

    </svg>

2 个答案:

答案 0 :(得分:2)

考虑到SMIL不能跨浏览器工作,我建议您使用CSS动画

动画颜色none无效,请使用transparent

body {
  background: gray;
}
.cls-1 {
  fill: transparent;
  stroke: #fff;
  stroke-miterlimit: 10;
  stroke-width: 2px;
  -webkit-animation-name: setcolor;
  -webkit-animation-duration: 2s;
  -webkit-animation-fill-mode: forwards;
  animation-name: setcolor;
  animation-duration: 2s;
  animation-fill-mode: forwards;
}
.cls-1:nth-child(2) {
  -webkit-animation-delay: .5s;
  animation-delay: .5s;
}
.cls-1:nth-child(3) {
  -webkit-animation-delay: 1s;
  animation-delay: 1s;
}

@keyframes setcolor {
  100% {
    fill: white;
  }
}
@-webkit-keyframes setcolor {
  100% {
    fill: white;
  }
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 129.57 26.18">
      <title>kropeczki</title>
      <g id="Warstwa_2" data-name="Warstwa 2">
        <g id="Layer_1" data-name="Layer 1">
          <circle class="cls-1" cx="13.09" cy="13.09" r="12.09">
          </circle>
          <circle class="cls-1" cx="64.79" cy="13.09" r="12.09">
          </circle>
          <circle class="cls-1" cx="116.49" cy="13.09" r="12.09">
          </circle>
        </g>
      </g>
</svg>

请注意,由于Chrome支持SMIL上的CSS / Web动画,因此SMIL的未来可能有些不可预测,所以我建议等待它使用它,直到它的未来更加安全。

答案 1 :(得分:1)

根据SVG和SMIL规范,持续时间不允许以句号开始。添加前导0作为规范要求使.7成为0.7修复Firefox中的东西。

我还添加了一个背景矩形,因为白色的白色在片段中没有显示得太好。

&#13;
&#13;
     <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 129.57 26.18">
          <defs>
            <style>.cls-1{fill:none;stroke:#fff;stroke-miterlimit:10;stroke-width:2px;}</style>
          </defs>
          <title>kropeczki</title>
          <g id="Warstwa_2" data-name="Warstwa 2">
            <rect width="100%" height="100%" fill="black"/>
            <g id="Layer_1" data-name="Layer 1">
              
              <circle class="cls-1" cx="13.09" cy="13.09" r="12.09">
            <animate
            attributeName="fill" from="none" to="#fff" begin="0.7" dur="0.1s" fill="freeze" repeatCount="1"/>  
              </circle>
              <circle class="cls-1" cx="64.79" cy="13.09" r="12.09">
                <animate
            attributeName="fill" from="none" to="#fff" begin="1" dur="0.1s" fill="freeze" repeatCount="1"/> 
              </circle>
              <circle class="cls-1" cx="116.49" cy="13.09" r="12.09">
                <animate
            attributeName="fill" from="none" to="#fff" begin="1.3" dur="0.1s" fill="freeze" repeatCount="1"/>
              </circle>
            </g>
          </g>
          
        </svg>
&#13;
&#13;
&#13;