Skip to content

1 #1

@ArkS0001

Description

@ArkS0001

Below is an updated version of your App.jsx that adds a background animation using [react-tsparticles](https://github.com/matteobruni/tsparticles). This example creates a new component called BackgroundAnimation.jsx and uses absolute positioning so the particle animation sits behind your main content.


1. Install the Dependency

In your project directory, run:

npm install react-tsparticles tsparticles

2. Create the BackgroundAnimation Component

Create a file named BackgroundAnimation.jsx (or similar) in your components folder and add the following code:

// BackgroundAnimation.jsx
import React from 'react';
import Particles from 'react-tsparticles';
import { loadFull } from 'tsparticles';

const BackgroundAnimation = () => {
  const particlesInit = async (main) => {
    // Loads the tsparticles package bundle for full functionality
    await loadFull(main);
  };

  return (
    <Particles
      init={particlesInit}
      options={{
        background: {
          color: {
            value: "#1a202c", // Dark background color
          },
        },
        fpsLimit: 60,
        interactivity: {
          events: {
            onClick: { enable: true, mode: "push" },
            onHover: { enable: true, mode: "repulse" },
            resize: true,
          },
          modes: {
            push: { quantity: 4 },
            repulse: { distance: 150, duration: 0.4 },
          },
        },
        particles: {
          color: { value: "#ffffff" },
          links: {
            color: "#ffffff",
            distance: 150,
            enable: true,
            opacity: 0.5,
            width: 1,
          },
          collisions: { enable: false },
          move: {
            direction: "none",
            enable: true,
            outModes: { default: "bounce" },
            random: false,
            speed: 2,
            straight: false,
          },
          number: {
            density: { enable: true, area: 800 },
            value: 50,
          },
          opacity: { value: 0.5 },
          shape: { type: "circle" },
          size: { random: true, value: 5 },
        },
        detectRetina: true,
      }}
    />
  );
};

export default BackgroundAnimation;

3. Update App.jsx

Now modify your App.jsx file to include the background animation behind your content. Notice that we wrap the main content inside a container with relative positioning and add an absolutely positioned div for the particles:

// App.jsx
import React from 'react';
import TechRadar from './components/TechRadar';
import QuadrantExplanations from './components/QuadrantExplanations/QuadrantExplanations';
import RingDefinitions from './components/RingDefinitions/RingDefinitions';
import { radarData } from './data/radarData';
import BackgroundAnimation from './components/BackgroundAnimation';

function App() {
  return (
    <div className="relative min-h-screen">
      {/* Background Animation */}
      <div className="absolute inset-0 z-0">
        <BackgroundAnimation />
      </div>
      
      {/* Main content */}
      <div className="relative z-10 flex flex-col items-center p-4 max-w-4xl mx-auto">
        <h1 className="text-2xl font-bold mb-4">Tech Radar</h1>
        <p className="mb-4 text-center text-gray-600"></p>
        <TechRadar data={radarData} />
        <QuadrantExplanations />
        <RingDefinitions />
      </div>
    </div>
  );
}

export default App;

Explanation

  • BackgroundAnimation.jsx:
    This component uses the react-tsparticles library to render an animated particle background. The options provided define a dark background with white particles that interact on hover and click.

  • App.jsx Modifications:

    • The outermost <div> has relative positioning with a minimum height of the viewport (min-h-screen).
    • An absolutely positioned <div> (with inset-0 and z-0) holds the background animation.
    • The main content is wrapped in a <div> with relative z-10 so that it overlays the animation.

This setup gives your application a more immersive, dynamic background while keeping your primary UI elements in focus.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions