首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击按钮时切换SVG动画效果

单击按钮时切换SVG动画效果
EN

Stack Overflow用户
提问于 2015-09-07 04:34:46
回答 1查看 2K关注 0票数 3

我是一个SVG初学者,所以请容忍我。

基本上,我希望动画一个三角形,从上到下移动时,点击和移动从下到上,如果再次点击。

我的问题是,现在我只能从上到下移动一个三角形,点击它。有人能提出解决这个问题的办法吗?如有任何指导,将不胜感激。

代码语言:javascript
复制
<svg viewBox="0 0 24 24" preserveAspectRatio="none">
  <polygon points="2,-5  12,6  22,-5" fill="#000">
    <animate attributeName="points" attributeType="XML"
         from="2,-5  12,6  22,-5"  to="2,0  12,11  22,0"
         begin="click" dur="0.5s"
         fill="freeze">
    </animate>
  </polygon>
</svg>

或单击此链接:小提琴

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-07 08:48:46

这是SMIL的唯一答案。如果您想要IE支持,添加fakeSmile

代码语言:javascript
复制
<svg viewBox="0 0 24 24" preserveAspectRatio="none">
  <polygon points="2,0  12,11  22,0" fill="#000" display="none">
    <animate id="a2" attributeName="points" attributeType="XML"
         from="2,0  12,11  22,0"  to="2,-5  12,6  22,-5"
         begin="click" dur="0.5s"
         fill="freeze">
    </animate>
    <set attributeName="display" to="block" begin="a1.end" fill="freeze" />
    <set attributeName="display" to="none" begin="a2.end" fill="freeze" />
    <set attributeName="points" to="2,0  12,11  22,0" begin="a2.end" fill="freeze" />
  </polygon>
  <polygon points="2,-5  12,6  22,-5" fill="#000">
    <animate id="a1" attributeName="points" attributeType="XML"
         from="2,-5  12,6  22,-5"  to="2,0  12,11  22,0"
         begin="click" dur="0.5s"
         fill="freeze">
    </animate>
    <set attributeName="display" to="none" begin="a1.end" fill="freeze" />
    <set attributeName="points" to="2,-5  12,6  22,-5" begin="a1.end" fill="freeze" />
    <set attributeName="display" to="block" begin="a2.end" fill="freeze" />
  </polygon>
</svg>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32431156

复制
相关文章

相似问题

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