【问题标题】:Why has my SMIL animation stopped working?为什么我的 SMIL 动画停止工作?
【发布时间】:2015-01-24 11:03:54
【问题描述】:

我做了一个简单的loading icon,六个矩形依次变暗,我的图像是:

<svg xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 viewBox="0 0 60 60">
 <g transform="translate(30,30)">
  <g transform="rotate(0)">
   <rect id="rect1" x="-3" y="9" rx="3" ry="3" width="6" height="20">
    <animateColor id="a1b" begin="0s;a6b.end" attributeName="fill" values="white;black" fill="freeze" dur=".5s" />
    <animateColor id="a1w" begin="1s;a6w.end" attributeName="fill" values="black;white" fill="freeze" dur=".5s" />
   </rect>
  </g>
  <g transform="rotate(60)">
   <rect id="rect2" x="-3" y="9" rx="3" ry="3" width="6" height="20">
    <animateColor id="a2b" begin="a1b.end" attributeName="fill" values="white;black" fill="freeze" dur=".5s" />
    <animateColor id="a2w" begin="a1w.end" attributeName="fill" values="black;white" fill="freeze" dur=".5s" />
   </rect>
  </g>
  ⋮
  <g transform="rotate(300)">
   <rect id="rect6" x="-3" y="9" rx="3" ry="3" width="6" height="20">
     <animateColor id="a6b" begin="a5b.end" attributeName="fill" values="white;black" fill="freeze" dur=".5s" />
     <animateColor id="a6w" begin="a5w.end" attributeName="fill" values="black;white" fill="freeze" dur=".5s" />
   </rect>
  </g>
 </g>
</svg>

当我最初创建文档时,这种结构是有效的。现在没有了。有人知道为什么吗?

【问题讨论】:

    标签: animation svg smil


    【解决方案1】:

    The &lt;animateColor&gt; elements was deprecated in SVG 1.1 并且正在为 SVG 2 完全删除。一些浏览器已经将其删除。

    要达到相同的效果,只需使用具有所有相同属性的&lt;animate&gt;

    <svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         viewBox="0 0 60 60" style="width:100vmin">
      <defs>
        <title>Loading Icon</title>
        <style type="text/css">
          rect {
            stroke: black;
            stroke-width: .75;
            fill: transparent;
          }
        </style>
        <rect id="bar" x="-3" y="9" rx="3" ry="3" width="6" height="20"/>
      </defs>
      <g transform="translate(30,30)">
        <g transform="rotate(0)">
          <rect id="rect1" x="-3" y="9" rx="3" ry="3" width="6" height="20">
            <animate id="a1b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="0s;a6b.end" />
            <animate id="a1w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="1s;a6w.end" />
          </rect>
        </g>
        <g transform="rotate(60)">
          <rect id="rect2" x="-3" y="9" rx="3" ry="3" width="6" height="20">
            <animate id="a2b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a1b.end" />
            <animate id="a2w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a1w.end" />
          </rect>
        </g>
        <g transform="rotate(120)">
          <rect id="rect3" x="-3" y="9" rx="3" ry="3" width="6" height="20">
            <animate id="a3b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a2b.end" />
            <animate id="a3w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a2w.end" />
          </rect>
        </g>
        <g transform="rotate(180)">
          <rect id="rect4" x="-3" y="9" rx="3" ry="3" width="6" height="20">
            <animate id="a4b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a3b.end" />
            <animate id="a4w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a3w.end" />
          </rect>
        </g>
        <g transform="rotate(240)">
          <rect id="rect5" x="-3" y="9" rx="3" ry="3" width="6" height="20">
            <animate id="a5b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a4b.end" />
            <animate id="a5w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a4w.end" />
          </rect>
        </g>
        <g transform="rotate(300)">
          <rect id="rect6" x="-3" y="9" rx="3" ry="3" width="6" height="20">
            <animate id="a6b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a5b.end" />
            <animate id="a6w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a5w.end" />
          </rect>
        </g>
      </g>
    </svg>

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多