如何正确地将 json 文件包含到自定义 WP 主题中?

问题描述

我正在尝试在我的自定义 wp 主题中包含一个 lottie 动画。我遇到的问题是我的路径由于某种原因没有找到 json 文件。这是一些代码

 <div class="container container__grid container__grid--justify-center">
     <div class="plant" data-file='plant'></div>
 </div>

和js

let plant = document.getElementsByClassName("plant");

Array.prototype.forEach.call(plant,(icon) => {
  console.log(icon.dataset.file);

  var anim = bodymovin.loadAnimation({
    container: icon,path: `lottie/${icon.dataset.file}.json`,renderer: "svg",loop: false,autoplay: false,});
  console.log(anim.path);

  icon.addEventListener("mouseenter",() => {
    anim.setDirection(1);
    anim.play();
  });
  icon.addEventListener("mouseleave",() => {
    anim.setDirection(-1);
    anim.play();
  });
});

我将我的 lottie 文件放在根目录中,以使路径尽可能直截了当,但仍然没有找到。我还附上了控制台错误的屏幕截图。

enter image description here

如何在我的自定义 wp 主题中正确地包含抽奖动画?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)