javascript - 在 webpack 中使用 lottie 库?
问题描述
我第一次在我的 webpack 项目中使用 Lottie 遇到了一个问题。
正如我通常所做的那样,我将带有 Lottie src 路径的脚本标签放在 body 标签的末尾,但这导致控制台中出现错误:bodymovin is not defined at...
我认为是因为我使用的是 webpack,所以在我的 index.js 之后加载了 Lottie 脚本?我不确定我应该把我的脚本标签放在哪里。
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="container">
<canvas id="canvas" width="200" height="200"></canvas>
</div>
<h1>Test</h1>
<button class="button">Press me to light led</button>
<p class="potentiometer"></p>
<div class="bm"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.5.9/lottie.min.js"></script>
</body>
</html>
const init = () => {
const bm = document.querySelector('.bm');
const anim = bodymovin.loadAnimation({
container: bm,
path: `../assets/eye.json`,
renderer: 'canvas',
loop: true,
autoplay: true
})
解决方案
推荐阅读
- testing - 如何检查反应组件是否在测试中恰好包含三个输入
- c - 寻找给定对的解决方案(因子的数量,素因子的数量)
- python - 使用 gRPC 发送 Keras 模型
- liferay - Liferay 门户 jquery 有时无法正常工作
- azure-devops - 我们可以使用 Azure DevOps 在 Databricks 上进行持续集成和交付吗
- json - 如何使 FormSet JSON 可序列化?
- python - 如何让 Camelot 读取已打开为“rb”的 pdf 文件
- angular - 是否可以将库重命名为 nx 中的包?
- stream - 在 Apache Flink 中的两个流上进行左连接的正确方法
- javascript - 如何在打字稿中使用 javascript 构造函数?