借助Lottie实现前端svg动图效果

时间:2025-04-08 15:08:28
  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • <title>svg animate</title>
  • <script src="/ajax/libs/bodymovin/5.10.1/" type="text/javascript"></script>
  • </head>
  • <body>
  • <div class="animation"></div>
  • </body>
  • <script>
  • const animation = bodymovin.loadAnimation({
  • container: document.querySelector('.animation'), // 需要渲染动画的dom元素
  • path: './氧气.json', // 动画文件
  • renderer: 'svg', // 渲染方式
  • loop: true, // 是否循环播放
  • autoplay: true, // 是否自动播放
  • name: "New Year", // 动画参考名称
  • })
  • </script>
  • </html>