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