Interactive Demo Documentation GitHub NPM
☀️
PLAY
Active Effect: Floating Hearts
Implementation Code
Loading...

📚 Interactive Developer Portal

Explore the full API specifications, package options, modular frameworks, and integration tutorials in our interactive workspace.

/ Introduction / Getting Started
Version 2.0.2

🚀 Getting Started

Install the lightweight, zero-dependency library using your favorite package manager to get fully compiled UMD and tree-shakable ES modules.

1. Package Installation

npm / node package manager
npm install @sarthak03dot/romantic-animations
pnpm / performant npm
pnpm add @sarthak03dot/romantic-animations
yarn / classic package manager
yarn add @sarthak03dot/romantic-animations

2. Quick Usage Example

Import the desired effect and trigger it in your application entry point. Make sure you have a target absolute or fixed container div prepared in your DOM:

import { startFloatingHearts } from '@sarthak03dot/romantic-animations'; // Trigger the effect on a fixed global canvas const session = startFloatingHearts('my-canvas-container', { count: 0.15, minSize: 18, maxSize: 32, glow: true });

✨ Library Features

Designed with professional modular mechanics and ultra-performance render loops to guarantee high-fidelity animations:

  • 🎨 12 Cinematic Particle Effects: Floating Hearts, Interactive Trails, Starfields, Magic fairy dust, Bokeh Orbs, Shooting Stars, Fireworks, glowing Butterflies, and more.
  • Zero Dependencies: Written entirely in pure, highly-optimized Vanilla JavaScript using hardware-accelerated 2D HTML5 canvas.
  • 📦 Universal Export Targets: Fully tree-shakable ES6 exports compatible with Vite/Webpack/Rollup alongside complete global UMD scripts.
  • 🔧 Real-time Customizability: Full parameters adjustments for colors, sizes, speeds, neon glow overlays, sinusoidal wobble, and drift rates.
  • 🧼 Memory-safe lifecycle handlers: Transparent garbage collection triggers preventing canvas and requestAnimationFrame leakage.

🧹 Session Management & Teardown

To support advanced Single Page Applications (React, Next.js), the library assigns a unique cryptographic or timestamp identifier to every launched animation container. This enables perfect garbage cleanup on page transitions.

1. Stopping a Specific Session

Store the returned Session ID when launching an animation, then pass it to the teardown method:

import { startFloatingHearts, stopAnimation } from '@sarthak03dot/romantic-animations'; // Start const sessionId = startFloatingHearts('animation-container'); // Terminate canvas, unbind listeners, and clear RAM stopAnimation(sessionId);

2. Global Teardown

If you want to clear absolutely all running overlays instantly, trigger the `stopAll` command:

import { stopAll } from '@sarthak03dot/romantic-animations'; // Terminate absolutely all active effects immediately stopAll();

🌐 Vanilla HTML / JS Setup

Perfect for static websites, landing pages, or rapid prototyping using a public jsDelivr CDN:

<!-- 1. Target Container --> <div id="canvas-target" style="position: fixed; inset: 0; pointer-events: none; z-index: 9999;"></div> <!-- 2. Load Global Object via CDN --> <script src="https://cdn.jsdelivr.net/npm/@sarthak03dot/romantic-animations/dist/romantic-animations.umd.js"></script> <!-- 3. Trigger --> <script> const id = RomanticAnimations.startFloatingHearts("canvas-target", { colors: ['#ff0a54', '#ff477e'], glow: true }); </script>

⚛️ React Component Lifecycle

To safely manage active canvas nodes in React components, perform canvas initialization inside React's `useEffect` hook and return a cleanup teardown trigger to prevent double-render leaks.

import { useEffect, useRef } from 'react'; import { startFloatingHearts, stopAnimation } from '@sarthak03dot/romantic-animations'; export default function HeartOverlay() { const containerRef = useRef(null); useEffect(() => { if (!containerRef.current) return; // Initialize passing the container DOM Node reference const id = startFloatingHearts(containerRef.current, { count: 0.1, colors: ['#ff4d6d', '#c77dff'] }); // Clean up on component unmount return () => stopAnimation(id); }, []); return <div ref={containerRef} style={{ position: 'fixed', inset: 0, pointerEvents: 'none', zIndex: 999 }} />; }

🛡️ Next.js SSR Hydration Guard

Next.js pre-renders components on the server where the global `window` browser context is unavailable. Shield initialization inside dynamic imports inside Client-Components.

'use client'; import { useEffect, useRef } from 'react'; export default function NextHeartOverlay() { const ref = useRef(null); useEffect(() => { let id = null; // Safely load and initialize only in the browser context import('@sarthak03dot/romantic-animations').then((mod) => { if (ref.current) { id = mod.startFloatingHearts(ref.current, { count: 0.12 }); } }); return () => { if (id !== null) { import('@sarthak03dot/romantic-animations').then(m => m.stopAnimation(id)); } }; }, []); return <div ref={ref} style={{ position: 'fixed', inset: 0, pointerEvents: 'none', zIndex: 999 }} />; }

💗 startFloatingHearts

Customizable heart nodes rising with sinusoidal horizontal drift.

startFloatingHearts(container, { count: 0.15, // Particle spawn frequency minSize: 15, // Min size in pixels maxSize: 30, // Max size in pixels colors: ['#ff4d6d', '#ff758f'], // Glowing color array wobble: true, // Wobble side to side glow: true // Shadow blur neon effect });

💘 startHeartTrail

Floating heart trails that track touch moves or mouse cursor coordinates.

startHeartTrail(container, { count: 1, // Spawns per mouse move minSize: 10, maxSize: 22, colors: ['#ff0a54', '#ff477e'], glow: true });

💥 startHeartBurst

Explosive burst of elements on clicks/taps anywhere inside the container.

startHeartBurst(container, { count: 12, // Particles generated per click minSize: 12, maxSize: 26, colors: ['#ff85a1', '#fbb1bd', '#f9bec7'], glow: true });

✨ startSparkles

Glowing, drifting 4-point cross-sparkles twinkling in space.

startSparkles(container, { count: 0.18, minSize: 8, maxSize: 22, colors: ['#ffffff', '#fff0f5', '#fff9e6'], glow: true });

🌧 startLoveRain

Falling shower of romantic symbols, emoji particles, and customizable characters.

startLoveRain(container, { count: 0.22, minSize: 14, maxSize: 28, colors: ['#ff4d6d', '#ff0a54'], glow: true });

🎉 startConfetti

Celebration confetti rain featuring physical gravity, drag, ribbons, and circular fragments.

startConfetti(container, { count: 0.3, minSize: 6, maxSize: 15, colors: ['#f72585', '#7209b7', '#3f37c9', '#4cc9f0'], glow: false });

🎆 startFireworks

Cinematic launching rockets with rocket drag trails, physics bursts, and glowing spark grids.

startFireworks(container, { count: 0.05, // Rocket spawn frequency minSize: 2, maxSize: 4, colors: ['#ff3366', '#33ccff', '#ffcc00', '#33ff66'], glow: true });

🌌 startStarField

Cosmic drifting stars with constellations and connection line bounds.

startStarField(container, { count: 0.12, minSize: 1, maxSize: 3.5, colors: ['#ffffff', '#add8e6', '#ffe4e1'], glow: true });

🦋 startButterflies

Flapping custom butterfly vectors drifting smoothly through space.

startButterflies(container, { count: 0.08, minSize: 12, maxSize: 28, colors: ['#9d4edd', '#c77dff', '#e0aaff'], glow: true });

✨ startMagicDust

Swirling magical fae dust following orbital wave tracks.

startMagicDust(container, { count: 0.15, minSize: 3, maxSize: 8, colors: ['#fff275', '#ff8c42', '#ff3c38'], glow: true });

🔮 startFloatingOrbs

Soft glowing bokeh spheres bouncing gently off walls.

startFloatingOrbs(container, { count: 0.1, minSize: 30, maxSize: 75, colors: ['#48cae4', '#90e0ef', '#ade8f4'], glow: true });

☄️ startShootingStars

Meteor trails flashing rapidly with customizable direction vectors.

startShootingStars(container, { count: 0.08, minSize: 1, maxSize: 3, colors: ['#ffffff', '#00b4d8', '#90e0ef'], glow: true });

🌹 startRosePetals

Simulates romantic red and pink rose petals falling and swirling in a gentle breeze. Includes 3D-like flipping effects.

startRosePetals(container, { density: 0.08, minSize: 15, maxSize: 30 });

🎈 startFloatingBalloons

Colorful celebratory balloons that slowly rise from the bottom of the screen with a gentle swaying motion.

startFloatingBalloons(container, { density: 0.02, minSize: 30, maxSize: 60 });

🌐 startGlobeMovement

3D Math projected particle globe

startGlobeMovement(container, { density: 0.1 });

🌸 startCherryBlossoms

Sakura petals falling with wind

startCherryBlossoms(container, { density: 0.15 });

🐛 startFireflies

Organically wandering glowing orbs

startFireflies(container, { density: 0.05 });

❄️ startSnowStorm

Winter snow falling gently

startSnowStorm(container, { density: 0.2 });

💻 startMatrixRain

Digital green rain

startMatrixRain(container, { density: 0.1 });

🍂 startAutumnLeaves

Autumn orange leaves spinning

startAutumnLeaves(container, { density: 0.1 });

🫧 startBubbles

Soap bubbles floating upwards

startBubbles(container, { density: 0.05 });

🕳️ startBlackHole

Spiraling cosmic gravity well

startBlackHole(container, { density: 0.15 });

🌌 startAuroraBorealis

Waving light bands

startAuroraBorealis(container, { density: 0.5 });

✨ startLensFlares

Cinematic anamorphic light flares

startLensFlares(container, { density: 0.1 });
Copied to clipboard!