-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 tsparticles2. 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 thereact-tsparticleslibrary 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>hasrelativepositioning with a minimum height of the viewport (min-h-screen). - An absolutely positioned
<div>(withinset-0andz-0) holds the background animation. - The main content is wrapped in a
<div>withrelative z-10so that it overlays the animation.
- The outermost
This setup gives your application a more immersive, dynamic background while keeping your primary UI elements in focus.