在Web Animation API中,我们可以通过Element.animate接口为元素设置动画。返回的Animation对象可以通过和播放.play()
、暂停或反转。.pause()
.reverse()
let img = document.querySelector('#happy-boy');
const boy_animation = [
{ transform: 'rotate(0)' },
{ transform: 'rotate(360deg)' },
];
const boy_timing = {
duration: 3000,
iterations: Infinity,
}
let animation = img.animate(boy_animation, boy_timing);
animation.reverse(); // <-- fails with DOM exception
当我尝试 reverse() 动画时出现此错误:
Cannot play reversed Animation with infinite target effect end.