使用requestAnimationFrame()方法创建一个动画函数,将JSON文件的数据传递给该函数,使用Web动画API创建一个SVG动画,并将JSON数据渲染到SVG动画中。
animate(keyframes, options)
const newspaperSpinning = [
{ transform: "rotate(0) scale(1)" },
{ transform: "rotate(360deg) scale(0)" },
];
const newspaperTiming = {
duration: 2000,
iterations: 1,
};
const newspaper = document.querySelector(".newspaper");
newspaper.addEventListener("click", () => {
newspaper.animate(newspaperSpinning, newspaperTiming);
});