【问题标题】:Lottie local animation not displaying on web pageLottie 本地动画未显示在网页上
【发布时间】:2023-03-17 13:55:01
【问题描述】:

我有一个简单的 html 来显示我在 After Effects 中制作的动画,但在本地加载时无法显示动画 (data.json)。但是,如果我通过 LottieFiles 上传动画并使用在我的 html 文件中生成的链接,它就可以工作。有人可以解释一下为什么我不能通过我的 data.json 而不是从生成的链接加载动画吗?

下面我放了到目前为止的代码:

<head>
    <!--  Meta  -->
    <meta charset="UTF-8">
    <title>Bodymovin Demo</title>
    <style>
        body {
            text-align: center;
        }
        h1 {
            margin-top: 2em;
        }
        #bm {
            width: 1000px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <h1>Test Animation</h1>

    <div id="bm"></div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.5.9/lottie.js"></script>
    <script>
        var animation = bodymovin.loadAnimation({
            container: document.getElementById('bm'),
            renderer: 'svg',
            loop: true,
            autoplay: true,
            // this way works, but if i put 'data.json' which is on the same directory of this file it doesn't work        
            path: 'https://assets7.lottiefiles.com/packages/lf20_kxQ49M.json'
        });
    </script>
</body>

我还有一个指向我的“data.json”文件的链接: https://drive.google.com/file/d/1xsikpLLQY-7FMV1_S5VelmB2_85LD-oi/view?usp=sharing

【问题讨论】:

  • 请注意,&lt;meta&gt; 标签不使用也不需要结束斜杠,并且在 HTML 中从来没有。
  • 感谢您的关注,从复制到这里,已修复,但问题依旧

标签: lottie bodymovin


【解决方案1】:

您很可能遇到了 CORS 错误。

出于安全原因,浏览器似乎不允许您加载存储在计算机上的 JSON 文件,只要 .json 文件在线托管,它就可以工作。

所以通过你已经完成的lottiefiles,或者在你的虚拟主机上。

【讨论】:

猜你喜欢
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-10
  • 1970-01-01
  • 2013-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多