|
| 1 | +function launchConfetti() { |
| 2 | + confetti({ |
| 3 | + spread: 360, |
| 4 | + ticks: 200, |
| 5 | + gravity: 1, |
| 6 | + decay: 0.94, |
| 7 | + startVelocity: 30, |
| 8 | + particleCount: 100, |
| 9 | + scalar: 3, |
| 10 | + shapes: ["image"], |
| 11 | + shapeOptions: { |
| 12 | + image: [ |
| 13 | + { src: "https://particles.js.org/images/fruits/apple.png", width: 32, height: 32 }, |
| 14 | + { src: "https://particles.js.org/images/fruits/avocado.png", width: 32, height: 32 }, |
| 15 | + { src: "https://particles.js.org/images/fruits/banana.png", width: 32, height: 32 }, |
| 16 | + { src: "https://particles.js.org/images/fruits/berries.png", width: 32, height: 32 }, |
| 17 | + { src: "https://particles.js.org/images/fruits/cherry.png", width: 32, height: 32 }, |
| 18 | + { src: "https://particles.js.org/images/fruits/grapes.png", width: 32, height: 32 }, |
| 19 | + { src: "https://particles.js.org/images/fruits/lemon.png", width: 32, height: 32 }, |
| 20 | + { src: "https://particles.js.org/images/fruits/orange.png", width: 32, height: 32 }, |
| 21 | + { src: "https://particles.js.org/images/fruits/peach.png", width: 32, height: 32 }, |
| 22 | + { src: "https://particles.js.org/images/fruits/pear.png", width: 32, height: 32 }, |
| 23 | + { src: "https://particles.js.org/images/fruits/pepper.png", width: 32, height: 32 }, |
| 24 | + { src: "https://particles.js.org/images/fruits/plum.png", width: 32, height: 32 }, |
| 25 | + { src: "https://particles.js.org/images/fruits/star.png", width: 32, height: 32 }, |
| 26 | + { src: "https://particles.js.org/images/fruits/strawberry.png", width: 32, height: 32 }, |
| 27 | + { src: "https://particles.js.org/images/fruits/watermelon.png", width: 32, height: 32 }, |
| 28 | + { src: "https://particles.js.org/images/fruits/watermelon_slice.png", width: 32, height: 32 }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + }); |
| 32 | +} |
| 33 | + |
| 34 | +function launchConfetti2() { |
| 35 | + confetti({ |
| 36 | + spread: 360, |
| 37 | + ticks: 200, |
| 38 | + gravity: 1, |
| 39 | + decay: 0.94, |
| 40 | + startVelocity: 30, |
| 41 | + particleCount: 100, |
| 42 | + scalar: 1, |
| 43 | + shapes: ["star"], |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +function launchConfetti3() { |
| 48 | + confetti({ |
| 49 | + spread: 360, |
| 50 | + ticks: 200, |
| 51 | + gravity: 1, |
| 52 | + decay: 0.94, |
| 53 | + startVelocity: 30, |
| 54 | + particleCount: 100, |
| 55 | + scalar: 1, |
| 56 | + shapes: ["square", "circle"], |
| 57 | + }); |
| 58 | +} |
| 59 | + |
| 60 | +function fireworks() { |
| 61 | + const duration = 15 * 1000, |
| 62 | + animationEnd = Date.now() + duration, |
| 63 | + defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 }; |
| 64 | + |
| 65 | + function randomInRange(min, max) { |
| 66 | + return Math.random() * (max - min) + min; |
| 67 | + } |
| 68 | + |
| 69 | + const interval = setInterval(function () { |
| 70 | + const timeLeft = animationEnd - Date.now(); |
| 71 | + |
| 72 | + if (timeLeft <= 0) { |
| 73 | + return clearInterval(interval); |
| 74 | + } |
| 75 | + |
| 76 | + const particleCount = 50 * (timeLeft / duration); |
| 77 | + |
| 78 | + confetti( |
| 79 | + Object.assign({}, defaults, { |
| 80 | + particleCount, |
| 81 | + origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 }, |
| 82 | + }) |
| 83 | + ); |
| 84 | + confetti( |
| 85 | + Object.assign({}, defaults, { |
| 86 | + particleCount, |
| 87 | + origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 }, |
| 88 | + }) |
| 89 | + ); |
| 90 | + }, 250); |
| 91 | +} |
0 commit comments