Hoai-Nho-Logo

/

Blog

AboutProjectsBlogContact

All topics

Architecture & Design

Architecture & Design
Discover cutting-edge architecture and design ideas. Explore innovative projects, modern interior design trends, sustainable architecture, and creative design solutions to inspire your next project.aws saa-c03
AWS

Explore best practices, tutorials, case studies, and insights on leveraging AWS’s vast ecosystem to build, deploy, and manage applications in the cloud

Design patterns

The Design Pattern category explores reusable solutions to common software design challenges, helping developers write efficient, maintainable, and scalable code

Docker
Explore essential Docker tutorials and resources. Find helpful tips, best practices, and tools to master containerization and improve your deployment workflow.
Security

The Security category focuses on best practices, tools, and frameworks essential for protecting applications, data, and infrastructure in an increasingly digital world

SSL license expired?

Ultimate Guide to Renewing SSL Certificates: Secure Your Website in 2024

Ensure your website stays secure! 🔒 Learn how to check, renew, and manage your SSL certificate to prevent security risks and downtime. Follow our step-by-step guide with best practices to keep your HTTPS protection active in 2024!

CSS

Database

Database
Find easy-to-follow guides on database SQL, NoSQL, PostgreSQL, and MySQL. Learn how to make databases that are fast and work well. Get tips to improve your skills. database
MySQL
Discover essential database guides covering SQL, NoSQL, and best practices. Get tips and performance benchmarks to improve your data management skills.
NoSQL
Discover essential database guides covering SQL, NoSQL, and best practices. Get tips and performance benchmarks to improve your data management skills.
PostgreSQL
Explore comprehensive PostgreSQL tutorials and resources. Find helpful tips, best practices, and performance benchmarks to enhance your database skills.
Search topic

LIKE vs Full-Text Search: SQL Performance and Use Cases

Explore the differences between SQL’s LIKE operator and Full-Text Search. Learn their syntax, performance, use cases, and advanced features for optimizing database queries

Generation

Interview Question

NodeJS

NodeJS
Explore beginner to advanced tutorials on JavaScript and TypeScript. Find helpful tips, best practices, and tools to create powerful web applications. typescript_vs_javascript
Javascript/Typescript
Learn JavaScript and TypeScript with easy guides. Discover tips, best practices, and tools to build efficient web applications quickly.
tripple-cache

🚀 Triple-Layered Web Caching Strategy: How Memory, IndexedDB and HTTP Cache Improved Speed by 96%

Discover how to accelerate your website through our powerful triple-layered caching strategy combining Memory Cache, IndexedDB, and HTTP Cache. Detailed guidance from theory to practice helps reduce page load time by up to 96%, improve user experience, and optimize performance across all devices.


© 2025 Hoai Nho. All rights reserved.

ContactGitHubLinkedIn
  1. Home
  2. /Blog
  3. /React Coin Celebration Animation Component | Interactive Particle Effects

React Coin Celebration Animation Component | Interactive Particle Effects

A high-performance React component that creates an engaging coin celebration animation using Framer Motion. Features dynamic particle systems, smooth transitions, and interactive effects perfect for gaming applications, reward celebrations, and interactive web experiences. Built with React 18+ and Framer Motion.

coin-celebration-effect
Hoài Nhớ@hoainho
January 19, 2025
|

2 min read

|

907 Views

Share:

Introduction

Today, we’ll explore how to create a spectacular coin celebration effect, similar to winning celebrations in casino games. This effect includes coins bursting outward and flying to a target point, accompanied by light effects and a backdrop animation.

Try to dive into the deep research demo on Playground

Technologies Used

  • ReactJS: UI and state management
  • Framer Motion: Smooth animations
  • TailwindCSS: Styling
  • Lodash: Utility functions

Prerequisites

  • Basic understanding of React Hooks (useState, useEffect)
  • Familiarity with TailwindCSS
  • Basic knowledge of animations and transforms

Component Analysis

1. Particle System
const ParticleSystem = ({ totalParticles, animatedCount, isActive, gcRef, onFirstCoinReachTarget }) => {
    // ... code
}

Main component managing the entire particle system. Props:

  • totalParticles: Total number of coins
  • animatedCount: Number of animated coins
  • gcRef: References to target points
  • onFirstCoinReachTarget: Callback when first coin reaches target
2. Animation Structure
a. Backdrop Effect
<motion.div
    className="fixed inset-0 bg-black/90 z-10"
    initial={{ opacity: 0 }}
    animate={{ 
        opacity: isVisibleGC ? 0.9 : 0,
        display: isVisibleGC ? "block" : "none"
    }}
    transition={{
        duration: 0.2,
        ease: "easeInOut"
    }}
/>
  • Creates a dark background with 0.9 opacity
  • Smooth fade in/out animation
b. Particle Animation
const calculateExplosionPath = (position, index, total) => {
    // Calculate particle path
    return {
        initial: { x: 0, y: 0, scale: 0.1 },
        explosion: { x: explosionX, y: explosionY, scale: 0.7 },
        collection: { x: locationX, y: locationY, scale: 0.3 }
    };
};

Animation divided into three phases:

  1. Initial: Starting position
  2. Explosion: Burst outward
  3. Collection: Flying to target
3. Animation Techniques
a. Sequence Player
const Particle = ({ frames, isAnimated }) => {
    const [currentFrame, setCurrentFrame] = useState(() => 
        Math.floor(random() * frames.length - 10)
    );

    useEffect(() => {
        if (isAnimated) {
            const interval = setInterval(() => {
                setCurrentFrame(prev => (prev + 1) % frames.length);
            }, 40);
            return () => clearInterval(interval);
        }
    }, [isAnimated, frames.length]);
    
    return <motion.img src={frames[currentFrame]} alt="particle" />;
};
  • Creates animation by switching frames
  • 40ms interval for 25fps
  • Random start frame for variety

b. Timing Control

const timing = {
    delay: index * 0.015,  // Delay between coins
    duration: 1.5         // Flight duration
};
  • Incremental delay creates sequential effect
  • Duration controls flight speed

Tips and Tricks

  1. Performance Optimization
// Use React.memo to prevent unnecessary re-renders
const Particle = React.memo(({ frames, isAnimated }) => {
    // ... code
});
  1. Dynamic Positioning
const getCircularPosition = (innerRadius, outerRadius) => {
    const angle = random() * Math.PI;
    const r = Math.sqrt(random() * (outerRadius ** 2 - innerRadius ** 2) + innerRadius ** 2);
    return {
        x: r * Math.cos(angle),
        y: r * Math.sin(angle)
    };
};
  • Generates random positions in a circle
  • Ensures even distribution
  1. Cleanup
useEffect(() => {
    let mounted = true;
    let timeouts = [];
    
    // ... code
    
    return () => {
        mounted = false;
        timeouts.forEach(clearTimeout);
    };
}, [isActive]);
  • Cleans up timeouts to prevent memory leaks
  • Checks mounted state before updates

Conclusion

This effect combines multiple techniques:

  • Particle systems
  • Frame-based animation
  • Motion transitions
  • Dynamic positioning
  • Timing control

For smooth effects, remember to:

  1. Synchronize animation timings
  2. Properly clean up resources
  3. Optimize performance with React.memo
  4. Use Framer Motion for complex animations

Further Learning Resources

  • Framer Motion Documentation
  • React Performance Optimization
  • TailwindCSS
  • JavaScript Animation Best Practices

This article helps you understand how to build a complex effect from basic concepts. Experiment and create your own variations!

Bonus Tips

  • Use transform instead of position properties for better performance
  • Implement progressive enhancement for slower devices
  • Consider adding sound effects for more impact
  • Test on different screen sizes and devices
  • Use requestAnimationFrame for smooth animations
  • Consider adding error boundaries for robustness

Remember, great animations enhance user experience but should never interfere with functionality. Always prioritize performance and accessibility in your implementations.


Tags:
AnimationCoin CelebrationFramer MotionReactJS
Written by

author
Hoài Nhớ

Hoài Nhớ

@Hoài Nhớ
AnimationCoin CelebrationFramer MotionReactJS

Table of Contents

    References posts

    Boosting Backend Performance with Distributed Cache: A Comprehensive Guide

    Learn how distributed caching with Redis can boost backend performance and scalability. This guide covers setup, caching strategies, and a step-by-step technical demo with benchmarks.

    Hoài Nhớ
    7 Essential Caching Strategies to Boost Backend Performance and Scalability

    Discover 6 powerful caching strategies to enhance backend performance and scalability. From in-memory and distributed caching to hybrid solutions, learn how to implement effective caching in your backend architecture for faster response times and optimized resource use

    Hoài Nhớ
    Master Gradient Text Animations: A Beginner-Friendly Guide with CSS

    Learn how to create stunning gradient text animations with smooth hover effects using simple CSS. Perfect for beginners, this guide provides step-by-step instructions and customization tips to enhance your website design

    Hoài Nhớ
    Related Posts

    distributed-caching
    Backend PerformanceCaching Strategies
    Boosting Backend Performance with Distributed Cache: A Comprehensive Guide

    Learn how distributed caching with Redis can boost backend performance and scalability. This guide covers setup, caching strategies, and a step-by-step technical demo with benchmarks.

    Hoài Nhớ
    Optimize Scalability with Cache
    Cachingcdn
    7 Essential Caching Strategies to Boost Backend Performance and Scalability

    Discover 6 powerful caching strategies to enhance backend performance and scalability. From in-memory and distributed caching to hybrid solutions, learn how to implement effective caching in your backend architecture for faster response times and optimized resource use

    Hoài Nhớ
    Text gradient effect
    Animation EffectGradient Text
    Master Gradient Text Animations: A Beginner-Friendly Guide with CSS

    Learn how to create stunning gradient text animations with smooth hover effects using simple CSS. Perfect for beginners, this guide provides step-by-step instructions and customization tips to enhance your website design

    Hoài Nhớ
    Clip-path for tags
    Advanced TagsClip-Path
    Creating Stylish Folded Tags in ReactJS Using Clip-Path

    The FoldedTag component is a versatile UI element designed to add a modern, folded-corner aesthetic to your React applications. By leveraging the power of CSS clip-path, this component creates intricate shapes like folded corners and pentagons, ensuring a unique and eye-catching design.

    Hoài Nhớ
    tripple-cache
    FrontendOptimizationIndexedDB
    🚀 Triple-Layered Web Caching Strategy: How Memory, IndexedDB and HTTP Cache Improved Speed by 96%

    Discover how to accelerate your website through our powerful triple-layered caching strategy combining Memory Cache, IndexedDB, and HTTP Cache. Detailed guidance from theory to practice helps reduce page load time by up to 96%, improve user experience, and optimize performance across all devices.

    Hoài Nhớ
    Redux Thunk and Saga
    Redux SagaRedux Thunk
    Redux Thunk vs Redux Saga: A Deep Dive into Strengths, Weaknesses, and Hidden Pitfalls

    This article explores the core differences between Redux Thunk and Redux Saga, highlighting their strengths, weaknesses, and best use cases. Whether you’re building a small application or managing complex asynchronous workflows, understanding these middleware options will help you make the right choice for your Redux architecture.

    Hoài Nhớ

    Subscribe to our newsletter

    Get the latest posts delivered right to your inbox