首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在React粒子JS中看不到图像

在React粒子JS中看不到图像
EN

Stack Overflow用户
提问于 2021-07-28 03:55:57
回答 1查看 47关注 0票数 0

我正在使用React Particle JS。我想让图像在粒子之间显示(如here - https://rpj.bembi.dev/#images),但看不到图像,只显示气泡。路径是正确的。我正在通过useEffect钩子包含pathseg.js脚本。

代码语言:javascript
复制
import Particles from "react-particles-js";
export default function Banner() {
  useEffect(() => {
    const script = document.createElement("script");
    script.src = "https://cdn.rawgit.com/progers/pathseg/master/pathseg.js";
    script.async = true;
    document.body.appendChild(script);
    return () => {
      document.body.removeChild(script);
    };
  }, []);
  return (
      <Particles
        params={{
          particles: {
            number: {
              value: 8,
              density: {
                enable: true,
                value_area: 800,
              },
            },
            line_linked: {
              enable: false,
            },
            move: {
              speed: 1,
              out_mode: "out",
            },
            shape: {
              type: ["image", "circle"],
              image: [
                {
                  src: "https://image.flaticon.com/icons/png/512/29/29495.png",
                  height: 20,
                  width: 20,
                },
              ],
            },
            color: {
              value: "#CCC",
            },
            size: {
              value: 30,
              random: false,
              anim: {
                enable: true,
                speed: 4,
                size_min: 10,
                sync: false,
              },
            },
          },
          retina_detect: false,
        }}
      />
  );
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-28 07:15:24

我认为使用带有image形状类型的数组有一个错误,如果你使用带有数组的images,它是有效的,image只处理单个对象,但我会检查它

代码语言:javascript
复制
import { useEffect } from "react";
import Particles from "react-particles-js";

export default function Banner() {
  useEffect(() => {
    const script = document.createElement("script");
    script.src = "https://cdn.rawgit.com/progers/pathseg/master/pathseg.js";
    script.async = true;
    document.body.appendChild(script);
    return () => {
      document.body.removeChild(script);
    };
  }, []);
  return (
      <Particles
        params={{
          particles: {
            number: {
              value: 8,
              density: {
                enable: true,
                value_area: 800,
              },
            },
            line_linked: {
              enable: false,
            },
            move: {
              speed: 1,
              out_mode: "out",
            },
            shape: {
              type: ["image", "circle"],
              image: {
                  src: "https://image.flaticon.com/icons/png/512/29/29495.png",
                  height: 20,
                  width: 20,
                },
            },
            color: {
              value: "#CCC",
            },
            size: {
              value: 30,
              random: false,
              anim: {
                enable: true,
                speed: 4,
                size_min: 10,
                sync: false,
              },
            },
          },
          retina_detect: false,
        }}
      />
  );
}

这是有效的,如果您需要多个图像,请将image更改为images

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68551078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档