首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否重新启动整个SVG animateTransform序列?

是否重新启动整个SVG animateTransform序列?
EN

Stack Overflow用户
提问于 2013-08-20 01:45:05
回答 2查看 1.8K关注 0票数 2

我有一个SVG图形,我是通过animateTransform动画。它会在屏幕上设置动画,然后一直显示在屏幕上,直到您单击它,然后它会缩小到0并且无法恢复。我想做的是在最后一个动画结束(缩放到0)后2秒内重新开始整个动画序列,这样它就会重新开始动画。

我该怎么做呢?谢谢!

代码语言:javascript
复制
<!-- Keep scaled at 0 on load -->
<animateTransform 
    attributeName="transform"
    attributeType="XML" 
    type="scale" 
    from="0" 
    to="0"
    dur="0.5s"/>
<!-- Scale up after 0.5 seconds -->
<animateTransform 
    attributeName="transform"
    attributeType="XML" 
    type="scale" 
    from="0" 
    to="1"  
    begin="0.5s"    
    dur="0.3s"
    fill="freeze"
    additive="sum"/>
<!-- Scale down on click -->
<animateTransform id="animatFinished"
    attributeName="transform"
    attributeType="XML" 
    type="scale" 
    from="1" 
    to="0" 
    begin="click" 
    dur="0.6s"
    fill="freeze"
    additive="sum"/>
EN

回答 2

Stack Overflow用户

发布于 2013-08-20 05:30:30

我们需要在onclick动画结束后的时间0和2秒开始第一个转换,这会得到begin="0s;animatFinished.end+2s"

第二个动画需要在第一个动画结束时开始,否则它只会触发一次。

additive="sum“的使用给你带来了问题,因为动画最终会试图向比例为0的对象添加比例,而当比例为0 x value =0时,它什么也不做。

所以,我想这就是你要找的:

代码语言:javascript
复制
<!-- Keep scaled at 0 on load -->
<animateTransform id="one"
    attributeName="transform"
    attributeType="XML" 
    type="scale" 
    from="0" 
    to="0"
    begin="0s;animatFinished.end+2s"
    dur="0.5s"
    fill="freeze"/>
<!-- Scale up after 0.5 seconds -->
<animateTransform
    attributeName="transform"
    attributeType="XML" 
    type="scale" 
    from="0" 
    to="1"  
    begin="one.end"
    dur="0.3s"
    fill="freeze"/>
<!-- Scale down on click -->
<animateTransform id="animatFinished"
    attributeName="transform"
    attributeType="XML" 
    type="scale" 
    from="1" 
    to="0" 
    begin="click" 
    dur="0.6s"
    fill="freeze"/>
票数 0
EN

Stack Overflow用户

发布于 2020-04-05 18:01:47

获取要重新启动的animateTransform元素并使用beginElement()方法

代码语言:javascript
复制
const animateEl = document.querySelector("#animatFinished");
animateEl.beginElement();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18319899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档