我试图让对象随着时间的推移越来越快地旋转,并且每次动画重复时都会触发事件。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));