【问题标题】:Particle.js not showing particles on ReactJS websiteParticle.js 没有在 ReactJS 网站上显示粒子
【发布时间】:2022-06-18 17:37:36
【问题描述】:

我一直在尝试在我的投资组合网站上实现 Particles.js,但相当不成功。这是我在库中运行的以下代码行:

npm i react-tsparticles

我无法将此包添加到我的网站,因此我尝试将其添加到新项目中。我尝试了 2 个不同的教程视频来添加它,但没有成功。这些是视频
https://www.youtube.com/watch?v=F20SxgG5MlM
https://www.youtube.com/watch?v=NO76xNYkNGk&t

This is how my page looks right now

This is how my page should look

这是我的粒子配置文件

const particlesConfig = {
  background: {
    color: "#6f32a8"
  },
  fullScreen: {
    enable: true,
    zIndex: -1
  },
  particles: {
    number: {
      value: 80,
      density: {
        enable: true,
        value_area: 800
      }
    },
    color: {
      value: "#ffffff"
    },
    shape: {
      type: "circle",
      stroke: {
        width: 0,
        color: "#000000"
      },
      polygon: {
        nb_sides: 5
      },
      image: {
        src: "img/github.svg",
        width: 100,
        height: 100
      }
    },
    opacity: {
      value: 0.5,
      random: false,
      anim: {
        enable: false,
        speed: 1,
        opacity_min: 0.1,
        sync: false
      }
    },
    size: {
      value: 3,
      random: true,
      anim: {
        enable: false,
        speed: 40,
        size_min: 0.1,
        sync: false
      }
    },
    line_linked: {
      enable: true,
      distance: 150,
      color: "#ffffff",
      opacity: 0.4,
      width: 1
    },
    move: {
      enable: true,
      speed: 3,
      direction: "none",
      random: false,
      straight: false,
      out_mode: "out",
      bounce: false,
      attract: {
        enable: false,
        rotateX: 600,
        rotateY: 1200
      }
    }
  },
  interactivity: {
    detect_on: "canvas",
    events: {
      onhover: {
        enable: false,
        mode: "repulse"
      },
      onclick: {
        enable: false,
        mode: "push"
      },
      resize: true
    },
    modes: {
      grab: {
        distance: 400,
        line_linked: {
          opacity: 1
        }
      },
      bubble: {
        distance: 400,
        size: 40,
        duration: 2,
        opacity: 8,
        speed: 3
      },
      repulse: {
        distance: 200,
        duration: 0.4
      },
      push: {
        particles_nb: 4
      },
      remove: {
        particles_nb: 2
      }
    }
  },
  retina_detect: true
};
export default particlesConfig;


这是我的背景组件

import React from 'react';
import Particles from "react-tsparticles";
import particlesConfig from '../config/particles-config.js';

const particleBackground = () => {
  return (
    <Particles options={particlesConfig} height="50vh" width='50vw'/>
  )
}

export default particleBackground


这是我的 App 组件

import React from "react";
import ParticleBackground from "./components/ParticleBackground";
import "./App.css"
const App = () => {
  return (
  <div className="App">
    <ParticleBackground/>
    <div className="particlesheader">
      <h1>Particle.JS</h1>
    </div>
  </div>
  );
};

export default App;

希望大家能帮帮我!谢谢!

【问题讨论】:

    标签: javascript reactjs particles.js react-particles-js


    【解决方案1】:

    我认为最新版本的 react-tsparticles 存在问题。
    this codesandbox react-tsparticles template 使用 1.40.2 版本,但 react-tsparticles 的最新版本是 2.0.6。我在代码沙箱中卸载了 1.40.2 并安装了 2.0.6,我意识到问题出在新版本上。
    所以我在我的项目中安装了 1.40.2 版本,它现在可以工作了。

    【讨论】:

      【解决方案2】:

      更改版本也对我有用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-18
        • 2019-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多