1 | [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
|
2 |
|
3 | # tsParticles Confetti Bundle
|
4 |
|
5 | [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-confetti/badge)](https://www.jsdelivr.com/package/npm/tsparticles-confetti) [![npmjs](https://badge.fury.io/js/tsparticles-confetti.svg)](https://www.npmjs.com/package/tsparticles-confetti) [![npmjs](https://img.shields.io/npm/dt/tsparticles-confetti)](https://www.npmjs.com/package/tsparticles-confetti) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
|
6 |
|
7 | [tsParticles](https://github.com/matteobruni/tsparticles) confetti bundle loads all the features necessary to create beautiful confetti effects with ease.
|
8 |
|
9 | **Included Packages**
|
10 |
|
11 | - [tsparticles-engine](https://github.com/matteobruni/tsparticles/tree/main/engine)
|
12 | - [tsparticles-move-base](https://github.com/matteobruni/tsparticles/tree/main/move/base)
|
13 | - [tsparticles-plugin-emitters](https://github.com/matteobruni/tsparticles/tree/main/plugins/emitters)
|
14 | - [tsparticles-plugin-motion](https://github.com/matteobruni/tsparticles/tree/main/plugins/motion)
|
15 | - [tsparticles-shape-cards](https://github.com/matteobruni/tsparticles/tree/main/shapes/cards)
|
16 | - [tsparticles-shape-circle](https://github.com/matteobruni/tsparticles/tree/main/shapes/circle)
|
17 | - [tsparticles-shape-heart](https://github.com/matteobruni/tsparticles/tree/main/shapes/heart)
|
18 | - [tsparticles-shape-image](https://github.com/matteobruni/tsparticles/tree/main/shapes/image)
|
19 | - [tsparticles-shape-polygon](https://github.com/matteobruni/tsparticles/tree/main/shapes/polygon)
|
20 | - [tsparticles-shape-square](https://github.com/matteobruni/tsparticles/tree/main/shapes/square)
|
21 | - [tsparticles-shape-star](https://github.com/matteobruni/tsparticles/tree/main/shapes/star)
|
22 | - [tsparticles-shape-text](https://github.com/matteobruni/tsparticles/tree/main/shapes/text)
|
23 | - [tsparticles-updater-color](https://github.com/matteobruni/tsparticles/tree/main/updaters/color)
|
24 | - [tsparticles-updater-life](https://github.com/matteobruni/tsparticles/tree/main/updaters/life)
|
25 | - [tsparticles-updater-opacity](https://github.com/matteobruni/tsparticles/tree/main/updaters/opacity)
|
26 | - [tsparticles-updater-out-modes](https://github.com/matteobruni/tsparticles/tree/main/updaters/outModes)
|
27 | - [tsparticles-updater-roll](https://github.com/matteobruni/tsparticles/tree/main/updaters/roll)
|
28 | - [tsparticles-updater-rotate](https://github.com/matteobruni/tsparticles/tree/main/updaters/rotate)
|
29 | - [tsparticles-updater-size](https://github.com/matteobruni/tsparticles/tree/main/updaters/size)
|
30 | - [tsparticles-updater-tilt](https://github.com/matteobruni/tsparticles/tree/main/updaters/tilt)
|
31 | - [tsparticles-updater-wobble](https://github.com/matteobruni/tsparticles/tree/main/updaters/wobble)
|
32 |
|
33 | ## How to use it
|
34 |
|
35 | ### CDN / Vanilla JS / jQuery
|
36 |
|
37 | The CDN/Vanilla version JS has two different files:
|
38 |
|
39 | - One is a bundle file with all the scripts included in a single file
|
40 | - One is a file including just the `confetti` function to load the tsParticles confetti bunddle, all dependencies must be
|
41 | included manually
|
42 |
|
43 | #### Bundle
|
44 |
|
45 | Including the `tsparticles.confetti.bundle.min.js` file will out of the box.
|
46 |
|
47 | This is the easiest usage, since it's a single file with all the features loaded.
|
48 |
|
49 | You can still add additional packages, loading them like all the other packages.
|
50 |
|
51 | #### Not Bundle
|
52 |
|
53 | This installation requires more work since all dependencies must be included in the page. Some lines above are all
|
54 | specified in the **Included Packages** section.
|
55 |
|
56 | ### Usage
|
57 |
|
58 | Once the scripts are loaded you can set up `tsParticles` like the following examples:
|
59 |
|
60 | ````javascript
|
61 |
|
62 | ** Easiest Way **
|
63 |
|
64 | ```javascript
|
65 | confetti()
|
66 | ````
|
67 |
|
68 | ** Async Way, best practice **
|
69 |
|
70 | ```javascript
|
71 | (async () => {
|
72 | await confetti();
|
73 | })();
|
74 | ```
|
75 |
|
76 | ** Confetti Options **
|
77 |
|
78 | ```javascript
|
79 | confetti("tsparticles", {
|
80 | /**
|
81 | * @deprecated use count property instead
|
82 | */
|
83 | particleCount: 50,
|
84 | /**
|
85 | * @deprecated use position property instead
|
86 | */
|
87 | origin: {
|
88 | x: 0.5,
|
89 | y: 0.5,
|
90 | },
|
91 | //------------------------------------------
|
92 | angle: 90,
|
93 | count: 50,
|
94 | position: {
|
95 | x: 50,
|
96 | y: 50,
|
97 | },
|
98 | spread: 45,
|
99 | startVelocity: 45,
|
100 | decay: 0.9,
|
101 | gravity: 1,
|
102 | drift: 0,
|
103 | ticks: 200,
|
104 | colors: ["#ffffff", "#ff0000"],
|
105 | shapes: ["square", "circle"],
|
106 | scalar: 1,
|
107 | zIndex: 100,
|
108 | disableForReducedMotion: true,
|
109 | });
|
110 | ```
|
111 |
|
112 | #### Options
|
113 |
|
114 | The `confetti` first parameter can be an id and the second parameter a single `options` object, or just the single options object without the id, which will be `confetti` by default. The `options` object has the following properties:
|
115 |
|
116 | - `count` _Integer (default: 50)_: The number of confetti to launch. More is always fun... but be cool, there's a lot of
|
117 | math involved. (`particleCount` can be used too, but it's deprecated)
|
118 | - `angle` _Number (default: 90)_: The angle in which to launch the confetti, in degrees: 90 is straight up.
|
119 | - `spread` _Number (default: 45)_: How far off center the confetti can go, in degrees. 45 means the confetti will launch
|
120 | at the defined `angle` plus or minus 22.5 degrees.
|
121 | - `startVelocity` _Number (default: 45)_: How fast the confetti will start going, in pixels.
|
122 | - `decay` _Number (default: 0.9)_: How quickly the confetti will lose speed. Keep this number between 0 and 1, otherwise
|
123 | the confetti will gain speed. Better yet, just never change it.
|
124 | - `gravity` _Number (default: 1)_: How quickly the particles are pulled down: 1 is full gravity, 0.5 is half gravity,
|
125 | etc., but there are no limits. You can even make particles go up if you'd like.
|
126 | - `drift` _Number (default: 0)_: How much to the side the confetti will drift. The default is 0, meaning that they will
|
127 | fall straight down. Use a negative number for left and positive number for right.
|
128 | - `ticks` _Number (default: 200)_: How many times the confetti will move. This is abstract... but play with it if the
|
129 | confetti disappear too quickly for you.
|
130 | - `position` _Object_: Where to start firing confetti from. Feel free to launch off-screen if you'd like. (`origin` can
|
131 | be used too, but it's deprecated)
|
132 | - `position.x` _Number (default: 50)_: The `x` position on the page, with `0` being the left edge and `100` being the
|
133 | right edge.
|
134 | - `position.y` _Number (default: 50)_: The `y` position on the page, with `0` being the top edge and `100` being the
|
135 | bottom edge.
|
136 | - `colors` _Array<String>_: An array of color strings, in the HEX format... you know, like `#bada55`.
|
137 | - `shapes` _Array<String>_: An array of shapes for the confetti. The possible values are:
|
138 | - `circle`
|
139 | - `square`
|
140 | - `star`
|
141 | - `polygon`
|
142 | - `image`
|
143 | - `heart`
|
144 | - `hearts`
|
145 | - `spades`
|
146 | - `clubs`
|
147 | - `diamonds`
|
148 | - `text`
|
149 | The default is to use both shapes in an even mix. You can even change the mix by providing a value such
|
150 | as `['circle', 'circle', 'square']` to use two third circles and one third squares.
|
151 | - `scalar` _Number (default: 1)_: Scale factor for each confetti particle. Use decimals to make the confetti smaller. Go
|
152 | on, try teeny tiny confetti, they are adorable!
|
153 | - `zIndex` _Integer (default: 100)_: The confetti should be on top, after all. But if you have a crazy high page, you
|
154 | can set it even higher.
|
155 | - `disableForReducedMotion` _Boolean (default: true)_: Disables confetti entirely for users
|
156 | that [prefer reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion).
|
157 |
|
158 | And for those asking, yes you can paste your canvas-confetti code and migrate to tsParticles Confetti without changing a thing
|