【问题标题】:Can svg animations be suspended without loosing accumulative information?svg动画可以暂停而不丢失积累的信息吗?
【发布时间】:2012-10-02 16:05:52
【问题描述】:

您可以无限制地停止和重复动画,但如果您重新启动一个不确定的动画,它将失去其累积值并从初始值开始。

也许我应该举个例子来说明一下;拿这个动画:

  <animate id="main"
    attributeName="transform" attributeType="XML"
    begin="startbox.click" dur="1s" end="endbox.click"
    from="rotate(0)" to="rotate(360)"
    additive="sum"
    accumulate="sum"
    fill="freeze"
    repeatCount="indefinite"
  />

如果我停止这个动画,并开始一个不同的动画(比如id="second")来影响同一个对象的旋转,second 将完美地从main 停止的地方继续。但是,如果我通过单击startbox(或任何其他事件)来启动这个,它将减去main 所做的所有差异并在开始之前重置旋转。

我想要的是一个适当的“暂停”,我可以在动画之前停止的地方继续。当然,我可以添加固定数量的相同动画和相同数量的相同开始/停止按钮来模拟效果,但这不是一个好的解决方案。特别是因为暂停的次数是有限的。


整个例子(似乎只适用于 Opera)

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
     xmlns="http://www.w3.org/2000/svg" version="1.1"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <desc>Click example</desc>
  <g>
    <rect id="startbox"
      x="10" y="10"
      width="20" height="20"
      stroke="none" fill="green"
    />
    <rect id="endbox"
      x="10" y="40"
      width="20" height="20"
      stroke="none" fill="red"
    />
    <g transform="translate(200,200)">
    <rect
      x="0" y="0"
      width="50" height="5"
      stroke="#10e9f3" fill="#30ffd0"
    >
      <animate
        attributeName="transform" attributeType="XML"
        begin="startbox.click" dur="1s" end="endbox.click"
        from="rotate(0)" to="rotate(360)"
        additive="sum"
        accumulate="sum"
        fill="freeze"
        repeatCount="indefinite"
      />
    </rect>
    </g>
  </g>
</svg>

【问题讨论】:

    标签: svg svg-animate


    【解决方案1】:

    它内置在 SVG 中

     SVGRoot.pauseAnimations();
    

    【讨论】:

    【解决方案2】:

    使用 animate 元素对变换进行动画处理是无效的,您必须使用 animateTransform。见http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties

    如果您的测试用例使用该 UA 进行动画处理,您应该向 Opera 报告您的测试用例。

      <animateTransform
        attributeName="transform" attributeType="XML"
        type="rotate"
        begin="startbox.click" dur="1s" end="endbox.click"
        from="0" to="360"
        additive="sum"
        accumulate="sum"
        fill="freeze"
        repeatCount="indefinite"
      />
    

    至于提出的问题,您可以pause animations using javascript,但据我所知,对于 SVG 1.1,您无法以声明方式进行。

    【讨论】:

    • 我最初是用rect.x 测试它,但这更容易看到。我会研究一下 JS,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 2016-03-27
    • 2021-03-07
    • 1970-01-01
    • 2012-05-04
    相关资源
    最近更新 更多