<div id="lottie"></div>

<div className="actions">
  <button class="button button__primary" id="play">Play</button>
  <button class="button button__potisive" id="pause">Pause</button>
  <button class="button button__secondary" id="stop">Stop</button>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  line-height: 1.5;
  font-size: 15px;
  font-weight: 400;
}

body {
  width: 100vw;
  min-height: 100vh;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;

  font-family: "Exo", Arial, sans-serif;
  background-color: #151522;
  color: #fff;
}

#lottie {
  margin-left: auto;
}

.actions {
  display: flex;
  justify-content: center;
  align-items: center;
}
.button {
  display: inline-flex;
  margin: 10px;
  padding: 12px 12px;
  cursor: pointer;
  user-select: none;
  transition: all 150ms linear;
  text-align: center;
  white-space: nowrap;
  color: #fff;
  border: 0 none;
  border-radius: 10rem;
  font-size: 1rem;
  font-weight: 500;
  appearance: none;
  justify-content: center;
  align-items: center;
  min-width: 160px;
  box-shadow: 0 0 2px 1px #e4e4e4;
}

.button:hover {
  transition: all 150ms linear;
  opacity: 0.85;
}

.button:active {
  transition: all 150ms linear;
  opacity: 0.75;
}

.button:focus {
  outline: 1px dotted #959595;
  outline-offset: -4px;
}

.button__primary {
  background: #416dea;
}

.button__potisive {
  background: #f32c52;
}

.button__secondary {
  background: #161616;
}
import bodymovin from "https://cdn.skypack.dev/lottie-web";

var animation = bodymovin.loadAnimation({
  // 动效加载到的DOM元素
  container: document.getElementById("lottie"), // 必须项
  // 包含动效的JSON文件的相对路径,也可以是绝对路径
  path:
    "https://www.w3cplus.com/sites/default/files/blogs/2021/2101/lottie-web.json",
  // 必须项,描述动效的JSON文件,一般由AE软件中导出的JSON文件
  // 动效渲染出来的格式,可以是svg、canvas和html
  renderer: "svg",
  // 必须项,除了svg选择之外还可以是canvas和html
  // 用于指定动效是否循环播放,true是循环播放,false不是循环播放
  loop: true, // 可选项
  // 指定动效是不是加载后就立即播放,true是立即播放,false不是立即播放
  autoplay: false, // 可选项
  // 指定动效的名称
  name: "mic animation" // 可选项
  // animationData与path互斥,是一个包含导出的动画数据的对象 // animationData: { // ... }
});

const PlayHander = document.getElementById("play");
const StopHander = document.getElementById("stop");
const PauseHander = document.getElementById("pause");

PlayHander.addEventListener("click", () => {
  animation.play();
});

PauseHander.addEventListener("click", () => {
  animation.pause();
});

StopHander.addEventListener("click", () => {
  animation.stop();
});
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.