DEV Community

Cover image for [JS] How to create beautiful and realistic confetti animation with tsParticles

[JS] How to create beautiful and realistic confetti animation with tsParticles

Matteo Bruni on June 29, 2021

Starting from version 1.30.0 tsParticles has new options to create beautiful and realistic confetti animations with every supported particle shape....
Collapse
 
markwright profile image
markwrightdev

Awesome effects! Thanks for sharing

Collapse
 
jonerikj profile image
jonerikj

This is great! Is it possible to have the animation stop after running for 30 seconds?

Collapse
 
matteobruni profile image
Matteo Bruni

You can set a timer and stop the animation

Collapse
 
jonerikj profile image
jonerikj

Thank you! Unfortunately I am very far from being a developer :P Any chance you could show how to include the timer inside the code? :)

Thread Thread
 
matteobruni profile image
Matteo Bruni
const container = await tsParticles.load("tsparticles", { /* your options */ });

setTimeout(() => {
  container.stop();
}, 5 /* seconds */ * 1000);
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
jonerikj profile image
jonerikj

Thank you. Where exactly do I place this in the code? Sorry for my lack of knowledge to coding.

Thread Thread
 
matteobruni profile image
Matteo Bruni

This is a replacement of the sample seen in the article. You have to keep the previous options, since I've cut them in the sample for readability.

Thread Thread
 
jonerikj profile image
jonerikj

Hmm 🤔 Still not able to make it work. Sorry for being a noob. I have tried placing this code in top and bottom of the js:
codepen.io/jon-erik-josephsen-the-...

Thread Thread
 
matteobruni profile image
Matteo Bruni

Ok you just missed the async function: codepen.io/matteobruni/pen/qBxvjLK

Or you can achieve something a little bit different using emitters life options: codepen.io/matteobruni/pen/eYVXRxR

Thread Thread
 
jonerikj profile image
jonerikj

Perfect! Thank you very much! 😁

Collapse
 
amircahyadi profile image
Amir-cahyadi

👍 ty