DEV Community

Cover image for Festive New Year Celebration with Fireworks, Confetti, and More! 🎉
Gladiators Battle
Gladiators Battle

Posted on

Festive New Year Celebration with Fireworks, Confetti, and More! 🎉

As we bid farewell to the old year and welcome the new, what better way to celebrate than with a delightful blend of animation, interactivity, and a touch of magic— all right in your browser?

I created a CodePen project (https://codepen.io/HanGPIIIErr/pen/MYgbbQV) that features sparkling fireworks triggered by your clicks, gentle confetti showers at the press of a button, a dynamic countdown to the New Year, and a surprise gift box waiting to be opened. On top of that, you’ll find a festive scene with a holiday tree, shimmering garlands, and an animated “ENJOY!” message to top it all off. The result is a charming, celebratory atmosphere that brings the holiday spirit to life on-screen.

Key Features

  1. Real-Time New Year Countdown Code Insight: We use JavaScript’s setInterval and Date objects to calculate the time remaining until midnight of the next year. By continuously updating the DOM elements every second, we keep the countdown accurate and engaging.
function updateCountdown() {
  const now = new Date();
  const nextYear = now.getFullYear() + 1;
  const newYear = new Date(nextYear, 0, 1, 0, 0, 0);
  const diff = newYear - now;

  const days = Math.floor(diff / (1000 * 60 * 60 * 24));
  const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
  const minutes = Math.floor((diff / (1000 * 60)) % 60);
  const seconds = Math.floor((diff / 1000) % 60);

  document.getElementById('days').textContent = String(days).padStart(2, '0');
  document.getElementById('hours').textContent = String(hours).padStart(2, '0');
  document.getElementById('minutes').textContent = String(minutes).padStart(2, '0');
  document.getElementById('seconds').textContent = String(seconds).padStart(2, '0');
}
setInterval(updateCountdown, 1000);
updateCountdown();
Enter fullscreen mode Exit fullscreen mode

This snippet keeps the user engaged, building anticipation as the New Year draws closer.

  1. Interactive Fireworks with tsParticles Technology: tsParticles Code Insight: By integrating tsParticles, we leverage a powerful library that renders and animates particles efficiently. We configure a “explode” mode on click events to produce a fireworks-like effect. Whenever you click on the screen, tsParticles generates a burst of glowing particles, simulating fireworks lighting up the night sky.
tsParticles.load("tsparticles", {
  "fullScreen": { "enable": true, "zIndex": -1 },
  "particles": {
    "number": { "value": 0 },
    "shape": { "type": "circle" },
    "color": { "value": "#fbd500" },
    "size": { "value": 3, "random": true },
    "move": { "enable": true, "speed": 6, "out_mode": "destroy" }
  },
  "interactivity": {
    "events": {
      "onclick": {
        "enable": true,
        "mode": "explode"
      }
    },
    "modes": {
      "explode": {
        "particles": { "min": 20, "max": 40 }
      }
    }
  },
  "background": {
    "image": "url('https://images.unsplash.com/photo-1513216484376-73bed57b2f27?fit=crop&w=1400&q=80')",
    "position": "center",
    "repeat": "no-repeat",
    "size": "cover"
  }
});
Enter fullscreen mode Exit fullscreen mode
  1. Confetti Showers on Demand Code Insight: A simple button, when clicked, triggers a function that dynamically generates 100 confetti elements. Each confetti has random positions and durations, creating a spontaneous, cheerful shower. After a few seconds, they are removed from the DOM to prevent clutter.
function triggerConfetti() {
  for (let i = 0; i < 100; i++) {
    const confetti = document.createElement('div');
    confetti.classList.add('confetti');
    const colors = ['blue', 'red', 'green'];
    confetti.classList.add(colors[Math.floor(Math.random()*colors.length)]);

    confetti.style.left = Math.random() * 100 + 'vw';
    confetti.style.animationDuration = (Math.random() * 3 + 2) + 's';
    confettiContainer.appendChild(confetti);

    setTimeout(() => {
      confetti.remove();
    }, 5000);
  }
}
Enter fullscreen mode Exit fullscreen mode
  1. Festive Scene & Décor Code Insight: The scene is composed of pure HTML and CSS— a CSS-styled tree with layers, a trunk, a twinkling star at the top, and garlands that subtly animate. The background image from Unsplash sets a celebratory mood, creating a warm, engaging environment for users.

In CSS, keyframes and transitions bring these elements to life:

.tree .star {
  animation: twinkle 2s infinite alternate;
}

@keyframes twinkle {
  from { opacity: 1; }
  to { opacity: 0.4; }
}
Enter fullscreen mode Exit fullscreen mode

Similarly, garlands use animations to change their brightness, adding to the festive spirit.

  1. Surprise Gift Reveal Code Insight: A neatly wrapped gift box (structured with HTML and styled with CSS) waits for a click. On opening (triggered by a simple class toggle), it reveals a holiday message and sets off another burst of confetti. This adds an extra layer of interaction, making users feel rewarded for exploring the scene.
const gift = document.getElementById('gift');
gift.addEventListener('click', () => {
  gift.classList.toggle('opened');
  triggerConfetti(); // Additional confetti when opening the gift
});
Enter fullscreen mode Exit fullscreen mode
  1. Animated “ENJOY!” Message Code Insight: Using a sequence of ... elements and CSS transitions, each letter drops in with a slight delay. This creates a captivating text animation that feels lively and positive, reinforcing the theme of celebration.
.text-animation .letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(-100%);
  animation: dropLetter 1.5s ease forwards;
}
@keyframes dropLetter {
  0% {transform: translateY(-100%); opacity: 0;}
  60% {opacity: 1;}
  100% {transform: translateY(0); opacity:1;}
}
Enter fullscreen mode Exit fullscreen mode

By staggering the animation times (e.g., using :nth-child() selectors), each letter lands one after the other, ensuring a delightful reveal.

Technologies Used

  • HTML/CSS: Lays the foundation for the entire scene— from the countdown layout, tree, garlands, and gift box, to the text animation.
  • JavaScript: Handles the logic for the countdown timer, event listeners for fireworks, button-triggered confetti, and gift interactions.
  • tsParticles: Makes implementing interactive, dynamic particle effects (fireworks) a breeze.

Customization Ideas

  • Change the Background Image: Update the background.image property in the tsParticles configuration to a different URL from Unsplash or your own images.
  • Adjust Particle Colors: Modify the color values for both confetti and fireworks to match a specific holiday palette (e.g., shades of green and red for Christmas, or blue and white for Hanukkah).
  • Personalize the Message: Edit the gift’s message to include personal greetings, notes of gratitude, or even a link to a personal portfolio or milestone. CodePen Link Check out the full creation here: https://codepen.io/HanGPIIIErr/pen/MYgbbQV

Experiment with the code, customize the visuals, and see what kind of unique seasonal scene you can create!

🌌 Conclusion: Forging the Future of Gladiators Battle

The latest enhancements to this festive CodePen project mark a significant leap toward providing an even more immersive and captivating web experience. By exploring dynamic particle systems, interactive DOM elements, and smooth CSS animations, we’re setting the stage for more ambitious creative coding projects.

Whether you’re a newcomer experimenting with interactive front-end concepts or a seasoned developer perfecting your design skills, these techniques ensure everyone can build their own epic holiday scenes and beyond.

🔗 Join the Journey!

We are actively seeking feedback from developers and creators alike. Dive into the project and share your thoughts:

🌍 Website: https://gladiatorsbattle.com
🛡️ Support Us on Kickstarter: https://www.kickstarter.com/projects/gladiatorsbattle/gladiators-battle-forge-your-legend-in-the-ultimate-arena
🐦 Follow Us on X (formerly Twitter): https://x.com/GladiatorsBT
💼 Connect on LinkedIn: https://www.linkedin.com/in/pierre-romain-lopez
🎮 Join the Community on Discord: https://discord.gg/YBNF7KjGwx
Thank you for your unwavering support as we continue to develop and enhance these creative digital experiences. Your feedback, ideas, and enthusiasm are the driving forces behind our progress.

Let the adventure continue—Ave, Gladiators! 🏺✨

If you have any questions or suggestions, please leave a comment below!

Top comments (0)