简体   繁体   English

如何在JavaScript中触发SVG动画(HTML)

[英]How to trigger a svg animation(html) in javascript

I am animating a rect in html/svg. 我正在为html / svg中的rect动画。 I have also created a function in javascript and I would like the animation to begin only when the function is called. 我还在javascript中创建了一个函数,我希望动画仅在调用该函数时才开始。

here's my code: 这是我的代码:

<svg>
<rect onclick="rightSide()" id="rightGreen" x="512" y="0" width="100%" height="768" fill="black" display="block">
       <animate id="openright"
                   attributeName="x"
                   from="512"
                   to="1536"
                   dur="5.5s"
                   repeatCount="1"
                   begin="indefinite"/>
    </rect>
</svg>

Everything works fine, however i need it to start when a function is called.? 一切正常,但是我需要它在调用函数时启动。

您在<animate>元素对象上调用beginElement()

document.getElementById("openright").beginElement()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM