Sparkles
An Animated Sparkles Effect Around div/section
An Animated Sparkles Effect Around div/section
To Get the Globe/Earth code Please Click That Link here
npm install @tsparticles/react @tsparticles/slim
1'use client';23import { useEffect, useId, useState } from 'react';4import Particles, { initParticlesEngine } from '@tsparticles/react';5import { loadSlim } from '@tsparticles/slim';67interface SparklesProps {8className?: string;9size?: number;10minSize?: number | null;11density?: number;12speed?: number;13minSpeed?: number | null;14opacity?: number;15direction?: string;16opacitySpeed?: number;17minOpacity?: number | null;18color?: string;19mousemove?: boolean;20hover?: boolean;21background?: string;22options?: Record<string, any>; // Adjust type as needed based on `options` structure23}2425export function Sparkles({26className,27size = 1.2,28minSize = null,29density = 800,30speed = 1.5,31minSpeed = null,32opacity = 1,33direction = '',34opacitySpeed = 3,35minOpacity = null,36color = '#ffffff',37mousemove = false,38hover = false,39background = 'transparent',40options = {},41}: SparklesProps) {42const [isReady, setIsReady] = useState(false);4344useEffect(() => {45initParticlesEngine(async (engine) => {46await loadSlim(engine);47}).then(() => {48setIsReady(true);49});50}, []);5152const id = useId();53const defaultOptions = {54background: {55color: {56value: background,57},58},59fullScreen: {60enable: false,61zIndex: 1,62},63fpsLimit: 300,6465interactivity: {66events: {67onClick: {68enable: true,69mode: 'push',70},71onHover: {72enable: hover,73mode: 'grab',74parallax: {75enable: mousemove,76force: 60,77smooth: 10,78},79},80resize: true as any,81},82modes: {83push: {84quantity: 4,85},86repulse: {87distance: 200,88duration: 0.4,89},90},91},92particles: {93color: {94value: color,95},96move: {97enable: true,98direction,99speed: {100min: minSpeed || speed / 130,101max: speed,102},103straight: true,104},105collisions: {106absorb: {107speed: 2,108},109bounce: {110horizontal: {111value: 1,112},113vertical: {114value: 1,115},116},117enable: false,118maxSpeed: 50,119mode: 'bounce',120overlap: {121enable: true,122retries: 0,123},124},125number: {126value: density,127},128opacity: {129value: {130min: minOpacity || opacity / 10,131max: opacity,132},133animation: {134enable: true,135sync: false,136speed: opacitySpeed,137},138},139size: {140value: {141min: minSize || size / 1.5,142max: size,143},144},145},146detectRetina: true,147};148return (149isReady && (150<Particles id={id}151// @ts-nocheck152options={defaultOptions} className={className} />153)154);155}
Prop | Type | Default | Description |
---|---|---|---|
className | string | Optional CSS class for styling the sparkles component. | |
size | number | 1.2 | Size of the sparkles. |
minSize | number | null | null | Minimum size of the sparkles, or null if no minimum size is set. |
density | number | 800 | Density of the sparkles. |
speed | number | 1.5 | Speed of the sparkles' animation. |
minSpeed | number | null | null | Minimum speed of the sparkles, or null if no minimum speed is set. |
opacity | number | 1 | Opacity of the sparkles. |
direction | string | '' | Direction of the sparkles' movement. |
opacitySpeed | number | 3 | Speed at which the opacity of the sparkles changes. |
minOpacity | number | null | null | Minimum opacity of the sparkles, or null if no minimum opacity is set. |
color | string | '#ffffff' | Color of the sparkles. |
mousemove | boolean | false | Whether the sparkles should follow the mouse movement. |
hover | boolean | false | Whether the sparkles should be active on hover. |
background | string | 'transparent' | Background color of the component. |
options | Record<string, any> | {} | Additional options for configuring the sparkles. |