You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know it uses an instance to reset the confetti but what about the example below?
I use that one to create a confetti canon like animation.
How to stop those?
// do this for 30 seconds
var duration = 30 * 1000;
var end = Date.now() + duration;
(function frame() {
// launch a few confetti from the left edge
confetti({
particleCount: 7,
angle: 60,
spread: 55,
origin: { x: 0 }
});
// and launch a few from the right edge
confetti({
particleCount: 7,
angle: 120,
spread: 55,
origin: { x: 1 }
});
// keep going until we are out of time
if (Date.now() < end) {
requestAnimationFrame(frame);
}
}());
The text was updated successfully, but these errors were encountered:
The example (which is from the demo page) uses code to continue launching more and more confetti. It does so by launching just 7 particles every 16 milliseconds. I assume that in this case, you tried calling confetti.reset() and saw that all the existing confetti went away but immediately, you got 7 more.
In this case, launching more and more confetti is done in your code (the example code in this case) and not in the confetti library, so you need to make sure that your code stops adding more confetti when you want to stop.
You could do something like this:
// do this for 30 secondsvarduration=30*1000;varend=Date.now()+duration;varrunning=true;(functionframe(){// launch a few confetti from the left edgeconfetti({particleCount: 7,angle: 60,spread: 55,origin: {x: 0}});// and launch a few from the right edgeconfetti({particleCount: 7,angle: 120,spread: 55,origin: {x: 1}});// keep going until we are out of timeif(Date.now()<end&&running){requestAnimationFrame(frame);}}());// some time latersetTimeout(function(){running=false;confetti.reset();},2000);
For someone who wants to have control on how to stop the confetti creation instantly, you can use this.
varreq=null;(functionframe(){// launch a few confetti from the left edgeconfetti({particleCount: 7,angle: 60,spread: 55,origin: {x: 0}});// and launch a few from the right edgeconfetti({particleCount: 7,angle: 120,spread: 55,origin: {x: 1}});// keep going until we are out of timeif(Date.now()<end&&running){req=requestAnimationFrame(frame);}}());// now when you want to stop, you can just call thiscancelAnimationFrame(req);
Hi, thanks for added the reset!
I know it uses an instance to reset the confetti but what about the example below?
I use that one to create a confetti canon like animation.
How to stop those?
The text was updated successfully, but these errors were encountered: