在重复循环结束时修改 SVG animateTransform
我试图让对象随着时间的推移旋转得越来越快,但每次动画重复时都会遇到事件触发问题。 SVG/SMIL 的 repeatEvent 似乎是我所需要的,但是在以下代码中,onSpinEnd()
似乎根本没有被调用。我做错了什么?
<path id='coloredPart' d='…'>
<animateTransform
id='spin'
attributeName='transform'
begin='0s'
dur='5s'
type='rotate'
from='0 0 0'
to='-360 0 0'
repeatCount='indefinite'
/>
</path>
<script> <![CDATA[
var spin = document.getElementById('spin');
var onSpinEnd = function() {
var intPart = 0;
intPart = parseInt(spin.getAttribute('dur')[0].slice(0, -1));
console.log(intPart);
if (intPart > 1) --intPart;
spin.setAttribute('dur', intPart.toString() + 's');
};
spin.addEventListener('repeatEvent', onSpinEnd, false)
]]>
</script>
事实证明, [0].slice(0, -1))
不会从“16s”中给出“16”; .slice(0, -1))
会的。该行应为:
intPart = parseInt(spin.getAttribute('dur').slice(0, -1));
I'm trying to make an object rotate faster and faster as time goes on, and I'm having trouble having an event fire every time the animation repeats itself. SVG/SMIL's repeatEvent seems to be what I need, but in the following code, onSpinEnd()
doesn't appear to be called at all. What am I doing wrong?
<path id='coloredPart' d='…'>
<animateTransform
id='spin'
attributeName='transform'
begin='0s'
dur='5s'
type='rotate'
from='0 0 0'
to='-360 0 0'
repeatCount='indefinite'
/>
</path>
<script> <![CDATA[
var spin = document.getElementById('spin');
var onSpinEnd = function() {
var intPart = 0;
intPart = parseInt(spin.getAttribute('dur')[0].slice(0, -1));
console.log(intPart);
if (intPart > 1) --intPart;
spin.setAttribute('dur', intPart.toString() + 's');
};
spin.addEventListener('repeatEvent', onSpinEnd, false)
]]>
</script>
As it turns out, [0].slice(0, -1))
won't give me "16" from "16s"; .slice(0, -1))
will. That line should read:
intPart = parseInt(spin.getAttribute('dur').slice(0, -1));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这片是做什么用的。这似乎适用于 Firefox。
此外,据我所知,目前只有 Opera 和 Firefox 会触发 SMIL 事件。
I'm not sure what the slice is for. This seems to work on Firefox.
Additionally, as far as I know only Opera and Firefox currently fire SMIL events.