UNPKG

5.14 kBMarkdownView Raw
1[![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
3# tsParticles Full Bundle
4
5[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles/badge)](https://www.jsdelivr.com/package/npm/tsparticles) [![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) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
7[tsParticles](https://github.com/matteobruni/tsparticles) full bundle loads all the v1 features to
8a `tsparticles-engine` instance.
9
10**Included Packages**
11
12- [tsparticles-engine](https://github.com/matteobruni/tsparticles/tree/main/engine)
13- [tsparticles-slim (and all its dependencies)](https://github.com/matteobruni/tsparticles/tree/main/bundles/slim)
14- [tsparticles-interaction-external-trail](https://github.com/matteobruni/tsparticles/tree/main/interactions/external/trail)
15- [tsparticles-plugin-absorbers](https://github.com/matteobruni/tsparticles/tree/main/plugins/absorbers)
16- [tsparticles-plugin-emitters](https://github.com/matteobruni/tsparticles/tree/main/plugins/emitters)
17- [tsparticles-updater-roll](https://github.com/matteobruni/tsparticles/tree/main/updaters/roll)
18- [tsparticles-updater-tilt](https://github.com/matteobruni/tsparticles/tree/main/updaters/tilt)
19- [tsparticles-updater-wobble](https://github.com/matteobruni/tsparticles/tree/main/updaters/wobble)
20
21## How to use it
22
23### CDN / Vanilla JS / jQuery
24
25The CDN/Vanilla version JS has two different files:
26
27- One is a bundle file with all the scripts included in a single file
28- One is a file including just the `loadFull` function to load the tsParticles full preset, all dependencies must be
29 included manually
30
31#### Bundle
32
33Including the `tsparticles.bundle.min.js` file will work exactly like `v1`, you can start using the `tsParticles`
34instance in the same way.
35
36This is the easiest usage, since it's a single file with the same `v1` features.
37
38All new features will be added as external packages, this bundle is recommended for migrating from `v1` easily.
39
40#### Not Bundle
41
42This installation requires more work since all dependencies must be included in the page. Some lines above are all
43specified in the **Included Packages** section.
44
45A note about `tsparticles-slim` can be made: it's not mandatory to include all of its dependencies, the slim bundle file
46is enough, and if this is done the `tsparticles-engine` is not needed, since it's already bundled in the slim bundle.
47
48### Usage
49
50Once the scripts are loaded you can set up `tsParticles` like this:
51
52```javascript
53(async () => {
54 await loadFull(tsParticles); // not needed if using the bundle script, required for any other installation
55
56 await tsParticles.load("tsparticles", {
57 /* options */
58 });
59})();
60```
61
62### React.js / Preact / Inferno
63
64_The syntax for `React.js`, `Preact` and `Inferno` is the same_.
65
66This sample uses the class component syntax, but you can use hooks as well (if the library supports it).
67
68_Class Components_
69
70```typescript jsx
71import React from "react";
72import Particles from "react-particles";
73import type { Engine } from "tsparticles-engine";
74import { loadFull } from "tsparticles";
75
76export class ParticlesContainer extends PureComponent<unknown> {
77 // this customizes the component tsParticles installation
78 async customInit(engine: Engine): Promise<void> {
79 // this adds the bundle to tsParticles
80 await loadFull(engine);
81 }
82
83 render() {
84 const options = {
85 /* custom options */
86 };
87
88 return <Particles options={options} init={this.customInit} />;
89 }
90}
91```
92
93_Hooks / Functional Components_
94
95```typescript jsx
96import React, { useCallback } from "react";
97import Particles from "react-particles";
98import type { Engine } from "tsparticles-engine";
99import { loadFull } from "tsparticles";
100
101export function ParticlesContainer(props: unknown) {
102 // this customizes the component tsParticles installation
103 const customInit = useCallback(async (engine: Engine) => {
104 // this adds the bundle to tsParticles
105 await loadFull(engine);
106 });
107
108 const options = {
109 /* custom options */
110 };
111
112 return <Particles options={options} init={this.customInit} />;
113}
114```
115
116### Vue (2.x and 3.x)
117
118_The syntax for `Vue.js 2.x` and `3.x` is the same_
119
120```vue
121<Particles id="tsparticles" :particlesInit="particlesInit" :options="options" />
122```
123
124```js
125const options = {
126 /* custom options */
127};
128
129async function particlesInit(engine: Engine): Promise<void> {
130 await loadFull(engine);
131}
132```
133
134### Angular
135
136```html
137<ng-particles [id]="id" [options]="options" [particlesInit]="particlesInit"></ng-particles>
138```
139
140```ts
141const options = {
142 /* custom options */
143};
144
145async function particlesInit(engine: Engine): Promise<void> {
146 await loadFull(engine);
147}
148```
149
150### Svelte
151
152```sveltehtml
153
154<Particles
155 id="tsparticles"
156 options={options}
157 particlesInit={particlesInit}
158/>
159```
160
161```js
162let options = {
163 /* custom options */
164};
165
166let particlesInit = async (engine) => {
167 await loadFull(engine);
168};
169```