UNPKG

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