【发布时间】: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
【问题讨论】:
-
请注意,
<meta>标签不使用也不需要结束斜杠,并且在 HTML 中从来没有。 -
感谢您的关注,从复制到这里,已修复,但问题依旧