1 | [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
|
2 |
|
3 | # tsParticles - TypeScript Particles
|
4 |
|
5 | **A lightweight TypeScript library for creating particles. Dependency free (\*), browser ready and compatible with
|
6 | React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Riot.js, Solid.js, and Web Components**
|
7 |
|
8 | [![Rate on Openbase](https://badges.openbase.com/js/rating/tsparticles.svg)](https://openbase.com/js/tsparticles?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge) [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles/badge?style=rounded)](https://www.jsdelivr.com/package/npm/tsparticles) [![Cdnjs](https://img.shields.io/cdnjs/v/tsparticles)](https://cdnjs.com/libraries/tsparticles) [![npmjs](https://badge.fury.io/js/tsparticles.svg)](https://www.npmjs.com/package/tsparticles) [![npm](https://img.shields.io/npm/dm/tsparticles)](https://www.npmjs.com/package/tsparticles) [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/) [![CodeFactor](https://www.codefactor.io/repository/github/matteobruni/tsparticles/badge)](https://www.codefactor.io/repository/github/matteobruni/tsparticles) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b983aaf3461a4c48b1e2eecce1ff1d74)](https://www.codacy.com/manual/ar3s/tsparticles?utm_source=github.com&utm_medium=referral&utm_content=matteobruni/tsparticles&utm_campaign=Badge_Grade)
|
9 |
|
10 | [![Slack](https://particles.js.org/images/slack.png)](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI) [![Discord](https://particles.js.org/images/discord.png)](https://discord.gg/hACwv45Hme) [![Telegram](https://particles.js.org/images/telegram.png)](https://t.me/tsparticles)
|
11 |
|
12 | [![tsParticles Product Hunt](https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=186113&theme=light)](https://www.producthunt.com/posts/tsparticles?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-tsparticles")
|
13 |
|
14 | ---
|
15 |
|
16 | ## Do you want to use it on your website?
|
17 |
|
18 | _Documentation and Development references [here](https://particles.js.org/docs/) 📖_
|
19 |
|
20 | **This library is available on the two most popular CDNs and it's easy and ready to use, if you were using particles.js
|
21 | it's even easier**.
|
22 |
|
23 | You'll find the
|
24 | instructions [below](https://github.com/matteobruni/tsparticles/blob/main/README.md#library-installation), with all the
|
25 | links you need, and _don't be scared by **TypeScript**, it's just the source language_.
|
26 |
|
27 | **The output files are just JavaScript**. 🤩
|
28 |
|
29 | CDNs and `npm` have all the sources you need in **Javascript**, a bundle browser ready (tsparticles.min.js) and all
|
30 | files splitted for `import` syntax.
|
31 |
|
32 | **If you are still interested** some lines below there are some instructions for migrating from the old particles.js
|
33 | library.
|
34 |
|
35 | ## **_Library installation_**
|
36 |
|
37 | ### **_Hosting / CDN_**
|
38 |
|
39 | **_Please use this hosts or your own to load tsParticles on your projects_**
|
40 |
|
41 | #### jsDelivr
|
42 |
|
43 | [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles/badge)](https://www.jsdelivr.com/package/npm/tsparticles)
|
44 |
|
45 | #### cdnjs
|
46 |
|
47 | [![Cdnjs](https://img.shields.io/cdnjs/v/tsparticles)](https://cdnjs.com/libraries/tsparticles)
|
48 |
|
49 | #### unpkg
|
50 |
|
51 | <https://unpkg.com/tsparticles/>
|
52 |
|
53 | ---
|
54 |
|
55 | ### **_npm_**
|
56 |
|
57 | [![npmjs](https://badge.fury.io/js/tsparticles.svg)](https://www.npmjs.com/package/tsparticles) [![npmjs](https://img.shields.io/npm/dt/tsparticles)](https://www.npmjs.com/package/tsparticles)
|
58 |
|
59 | ```shell
|
60 | npm install tsparticles
|
61 | ```
|
62 |
|
63 | ### **_yarn_**
|
64 |
|
65 | ```shell
|
66 | yarn add tsparticles
|
67 | ```
|
68 |
|
69 | #### Import and require
|
70 |
|
71 | Starting from version 1.12.11 `import` and `require` can be used to import `tsParticles` .
|
72 |
|
73 | Now you can write something like this
|
74 |
|
75 | ```javascript
|
76 | const tsParticles = require("tsparticles");
|
77 |
|
78 | // or
|
79 |
|
80 | import { tsParticles } from "tsparticles";
|
81 | ```
|
82 |
|
83 | The imported `tsParticles` is the same instance you have when including the script.
|
84 |
|
85 | ---
|
86 |
|
87 | ### **_NuGet_**
|
88 |
|
89 | [![Nuget](https://img.shields.io/nuget/v/tsParticles)](https://www.nuget.org/packages/tsParticles/)
|
90 |
|
91 | ---
|
92 |
|
93 | ### **_Usage_**
|
94 |
|
95 | Load tsParticles and configure the particles:
|
96 |
|
97 | [![tsParticles demo](https://media.giphy.com/media/ftHwBpp3b0qNyCXRuu/giphy.gif)](https://particles.js.org)
|
98 |
|
99 | **index.html**
|
100 |
|
101 | ```html
|
102 | <div id="tsparticles"></div>
|
103 |
|
104 | <script src="tsparticles.min.js"></script>
|
105 | ```
|
106 |
|
107 | **app.js**
|
108 |
|
109 | ```javascript
|
110 | // @path-json can be an object or an array, the first will be loaded directly, the object from the array will be random selected
|
111 | /* tsParticles.loadJSON(@dom-id, @path-json, @callback (optional)); */
|
112 |
|
113 | tsParticles
|
114 | .loadJSON("tsparticles", "presets/default.json")
|
115 | .then((container) => {
|
116 | console.log("callback - tsparticles config loaded");
|
117 | })
|
118 | .catch((error) => {
|
119 | console.error(error);
|
120 | });
|
121 |
|
122 | //or
|
123 |
|
124 | /* tsParticles.load(@dom-id, @options); */
|
125 |
|
126 | tsParticles.load("tsparticles", {
|
127 | /* options here */
|
128 | });
|
129 |
|
130 | //or
|
131 |
|
132 | /* tsParticles.loadFromArray(@dom-id, @options, @index (optional)); */
|
133 |
|
134 | tsParticles.loadFromArray("tsparticles", [
|
135 | {
|
136 | /* options here */
|
137 | },
|
138 | {
|
139 | /* other options here */
|
140 | },
|
141 | ]);
|
142 | //random object
|
143 |
|
144 | tsParticles.loadFromArray(
|
145 | "tsparticles",
|
146 | [
|
147 | {
|
148 | /* options here */
|
149 | },
|
150 | {
|
151 | /* other options here */
|
152 | },
|
153 | ],
|
154 | 1
|
155 | ); //the second one
|
156 | // Important! If the index is not in range 0...<array.length, the index will be ignored.
|
157 |
|
158 | // after initialization this can be used.
|
159 |
|
160 | /* tsParticles.setOnClickHandler(@callback); */
|
161 |
|
162 | /* this will be fired from all particles loaded */
|
163 |
|
164 | tsParticles.setOnClickHandler((event, particles) => {
|
165 | /* custom on click handler */
|
166 | });
|
167 |
|
168 | // now you can control the animations too, it's possible to pause and resume the animations
|
169 | // these methods don't change the config so you're safe with all your configurations
|
170 | // domItem(0) returns the first tsParticles instance loaded in the dom
|
171 | const particles = tsParticles.domItem(0);
|
172 |
|
173 | // play will start the animations, if the move is not enabled it won't enable it, it just updates the frame
|
174 | particles.play();
|
175 |
|
176 | // pause will stop the animations
|
177 | particles.pause();
|
178 | ```
|
179 |
|
180 | ---
|
181 |
|
182 | ## Official components for some of the most used frameworks
|
183 |
|
184 | ### Angular
|
185 |
|
186 | #### `ng-particles`
|
187 |
|
188 | [![npm](https://img.shields.io/npm/v/ng-particles)](https://www.npmjs.com/package/ng-particles) [![npm](https://img.shields.io/npm/dm/ng-particles)](https://www.npmjs.com/package/ng-particles)
|
189 |
|
190 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/angular/README.md)
|
191 |
|
192 | ### Inferno
|
193 |
|
194 | #### `inferno-particles`
|
195 |
|
196 | [![npm](https://img.shields.io/npm/v/inferno-particles)](https://www.npmjs.com/package/inferno-particles) [![npm](https://img.shields.io/npm/dm/inferno-particles)](https://www.npmjs.com/package/inferno-particles)
|
197 |
|
198 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/inferno/README.md)
|
199 |
|
200 | ### jQuery
|
201 |
|
202 | #### `jquery-particles`
|
203 |
|
204 | [![npm](https://img.shields.io/npm/v/jquery-particles)](https://www.npmjs.com/package/jquery-particles) [![npm](https://img.shields.io/npm/dm/jquery-particles)](https://www.npmjs.com/package/jquery-particles)
|
205 |
|
206 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/jquery/README.md)
|
207 |
|
208 | ### Preact
|
209 |
|
210 | #### `preact-particles`
|
211 |
|
212 | [![npm](https://img.shields.io/npm/v/preact-particles)](https://www.npmjs.com/package/preact-particles) [![npm](https://img.shields.io/npm/dm/preact-particles)](https://www.npmjs.com/package/preact-particles)
|
213 |
|
214 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/preact/README.md)
|
215 |
|
216 | ### ReactJS
|
217 |
|
218 | #### `react-tsparticles`
|
219 |
|
220 | [![npm](https://img.shields.io/npm/v/react-tsparticles)](https://www.npmjs.com/package/react-tsparticles) [![npm](https://img.shields.io/npm/dm/react-tsparticles)](https://www.npmjs.com/package/react-tsparticles)
|
221 |
|
222 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/react/README.md)
|
223 |
|
224 | ### Svelte
|
225 |
|
226 | #### `svelte-particles`
|
227 |
|
228 | [![npm](https://img.shields.io/npm/v/svelte-particles)](https://www.npmjs.com/package/svelte-particles) [![npm downloads](https://img.shields.io/npm/dm/svelte-particles)](https://www.npmjs.com/package/svelte-particles)
|
229 |
|
230 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/svelte/README.md)
|
231 |
|
232 | ### VueJS 2.x
|
233 |
|
234 | #### `particles.vue`
|
235 |
|
236 | [![npm](https://img.shields.io/npm/v/particles.vue)](https://www.npmjs.com/package/particles.vue) [![npm](https://img.shields.io/npm/dm/particles.vue)](https://www.npmjs.com/package/particles.vue)
|
237 |
|
238 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/vue/README.md)
|
239 |
|
240 | ### VueJS 3.x
|
241 |
|
242 | #### `particles.vue3`
|
243 |
|
244 | [![npm](https://img.shields.io/npm/v/particles.vue3)](https://www.npmjs.com/package/particles.vue3) [![npm](https://img.shields.io/npm/dm/particles.vue3)](https://www.npmjs.com/package/particles.vue3)
|
245 |
|
246 | You can find the instructions [here](https://github.com/matteobruni/tsparticles/blob/main/components/vue3/README.md)
|
247 |
|
248 | ---
|
249 |
|
250 | ## **_Demo / Generator_**
|
251 |
|
252 | <https://particles.js.org/>
|
253 |
|
254 | [![Particles demo](https://particles.js.org/images/demo.png?v=1.8.1)](https://particles.js.org/)
|
255 |
|
256 | ---
|
257 |
|
258 | ### Characters as particles
|
259 |
|
260 | [![Particles chars demo](https://media.giphy.com/media/JsssOXz72bM6jGEZ0s/giphy.gif)](https://particles.js.org/#chars)
|
261 |
|
262 | ---
|
263 |
|
264 | ### Mouse hover connections
|
265 |
|
266 | [![Particles mouse connections demo](https://media.giphy.com/media/XzvZThpVbxHxMYz5xt/giphy.gif)](https://particles.js.org/#connect)
|
267 |
|
268 | ---
|
269 |
|
270 | ### Polygon mask
|
271 |
|
272 | [![tsParticles Polygon Mask demo](https://media.giphy.com/media/lNRfiSgaMFbL4FMhW6/giphy.gif)](https://particles.js.org/#polygonMask)
|
273 |
|
274 | ---
|
275 |
|
276 | ### Animated stars
|
277 |
|
278 | [![Particles NASA demo](https://media.giphy.com/media/cLqGsnh7FKRVMgPIWE/giphy.gif)](https://particles.js.org/#nasa)
|
279 |
|
280 | ---
|
281 |
|
282 | ### Nyan cat flying on scrolling stars
|
283 |
|
284 | [![Particles Nyan Cat demo](https://media.giphy.com/media/LpX2oNc9ZMgIhIXQL9/giphy.gif)](https://particles.js.org/#nyancat2)
|
285 |
|
286 | ---
|
287 |
|
288 | ### Snow particles
|
289 |
|
290 | [![tsParticles Snow demo](https://media.giphy.com/media/gihwUFbmiubbkdzEMX/giphy.gif)](https://particles.js.org/#snow)
|
291 |
|
292 | ---
|
293 |
|
294 | ### Background Mask particles
|
295 |
|
296 | [![tsParticles Background Mask demo](https://media.giphy.com/media/dWraWgqInWFGWiOyRu/giphy.gif)](https://particles.js.org/#background)
|
297 |
|
298 | ---
|
299 |
|
300 | #### COVID-19 SARS-CoV-2 particles
|
301 |
|
302 | [![tsParticles COVID-19 demo](https://media.giphy.com/media/fsVN1ZHksgBIXNIbr1/giphy.gif)](https://particles.js.org/#virus)
|
303 |
|
304 | _Don't click! DON'T CLICK! OH NO IT'S SPREADING!!!!_
|
305 |
|
306 | **COVID-19 is a serious disease. Please stay at home, wear a mask and stay safe!**
|
307 |
|
308 | ---
|
309 |
|
310 | **particles.json**
|
311 |
|
312 | You can find a sample config [here](https://particles.js.org/docs/modules/_core_container_.html) 📖
|
313 |
|
314 | ---
|
315 |
|
316 | ## **_Options_**
|
317 |
|
318 | You can find all options
|
319 | available [here](https://particles.js.org/docs/interfaces/_options_interfaces_ioptions_.ioptions.html) 📖
|
320 |
|
321 | ## Want to see it in action and try it?
|
322 |
|
323 | I've created a tsParticles collection on [CodePen](https://codepen.io/collection/DPOage) 😮 or you can checkout
|
324 | my [profile](https://codepen.io/matteobruni)
|
325 |
|
326 | Otherwise there's the demo page link below. Just click/tap the Coronavirus below, don't be scared. **It's safe** 😷.
|
327 |
|
328 | [![tsParticles demo](https://media.giphy.com/media/fsVN1ZHksgBIXNIbr1/giphy.gif)](https://particles.js.org/#virus)
|
329 |
|
330 | Want to see ever more demos? Clone the repository on your computer and follow these instructions
|
331 |
|
332 | ```shell
|
333 | yarn install && yarn start
|
334 | ```
|
335 |
|
336 | **Boom! 💥** <http://localhost:3000> and you can checkout other demos.
|
337 |
|
338 | _If you are brave enough_ you can switch to the `dev` branch for trying the features under development.
|
339 |
|
340 | ---
|
341 |
|
342 | ## Migrating from Particles.js
|
343 |
|
344 | **tsParticles** library is fully compatible with the _particles.js_ configuration.
|
345 |
|
346 | Seriously, you just need to change the script source et-voilà , **you're ready** 🧙!
|
347 |
|
348 | You can read more **[here](https://dev.to/matteobruni/migrating-from-particles-js-to-tsparticles-2a6m)**
|
349 |
|
350 | Want to know 5 reasons to do the
|
351 | switch? [Read here](https://dev.to/matteobruni/5-reasons-to-use-tsparticles-and-not-particles-js-1gbe)
|
352 |
|
353 | _Below you can find all the information you need to install tsParticles and its new syntax._
|
354 |
|
355 | ---
|
356 |
|
357 | ## Plugins/Customizations
|
358 |
|
359 | tsParticles now supports some customizations 🥳.
|
360 |
|
361 | **You can create your own plugins**
|
362 |
|
363 | _Read more [here](https://particles.js.org/docs/modules/_core_interfaces_iplugin_.html)...\_
|