UNPKG

6.87 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)
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-engine](https://github.com/matteobruni/tsparticles/tree/main/engine)
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-particles-attract](https://github.com/matteobruni/tsparticles/tree/main/interactions/particles/attract)
23- [tsparticles-interaction-particles-collisions](https://github.com/matteobruni/tsparticles/tree/main/interactions/particles/collisions)
24- [tsparticles-interaction-particles-links](https://github.com/matteobruni/tsparticles/tree/main/interactions/particles/links)
25- [tsparticles-shape-circle](https://github.com/matteobruni/tsparticles/tree/main/shapes/circle)
26- [tsparticles-shape-image](https://github.com/matteobruni/tsparticles/tree/main/shapes/image)
27- [tsparticles-shape-line](https://github.com/matteobruni/tsparticles/tree/main/shapes/line)
28- [tsparticles-shape-polygon](https://github.com/matteobruni/tsparticles/tree/main/shapes/polygon)
29- [tsparticles-shape-square](https://github.com/matteobruni/tsparticles/tree/main/shapes/square)
30- [tsparticles-shape-star](https://github.com/matteobruni/tsparticles/tree/main/shapes/star)
31- [tsparticles-shape-text](https://github.com/matteobruni/tsparticles/tree/main/shapes/text)
32- [tsparticles-updater-angle](https://github.com/matteobruni/tsparticles/tree/main/updaters/angle)
33- [tsparticles-updater-color](https://github.com/matteobruni/tsparticles/tree/main/updaters/color)
34- [tsparticles-updater-life](https://github.com/matteobruni/tsparticles/tree/main/updaters/life)
35- [tsparticles-updater-opacity](https://github.com/matteobruni/tsparticles/tree/main/updaters/opacity)
36- [tsparticles-updater-out-modes](https://github.com/matteobruni/tsparticles/tree/main/updaters/outModes)
37- [tsparticles-updater-size](https://github.com/matteobruni/tsparticles/tree/main/updaters/size)
38- [tsparticles-updater-stroke-color](https://github.com/matteobruni/tsparticles/tree/main/updaters/strokeColor)
39
40## How to use it
41
42### CDN / Vanilla JS / jQuery
43
44The CDN/Vanilla version JS has two different files:
45
46- One is a bundle file with all the scripts included in a single file
47- One is a file including just the `loadSlim` function to load the tsParticles slim preset, all dependencies must be
48 included manually
49
50#### Bundle
51
52Including the `tsparticles.slim.bundle.min.js` file will work exactly like `v1`, you can start using the `tsParticles`
53instance in the same way.
54
55This is the easiest usage, since it's a single file with the some of the `v1` features.
56
57All new features will be added as external packages, this bundle is recommended for migrating from `v1` easily.
58
59#### Not Bundle
60
61This installation requires more work since all dependencies must be included in the page. Some lines above are all
62specified in the **Included Packages** section.
63
64### Usage
65
66Once the scripts are loaded you can set up `tsParticles` like this:
67
68```javascript
69loadSlim(tsParticles); // not needed if using the bundle script, required for any other installation
70
71tsParticles.load("tsparticles", {
72 /* options */
73});
74```
75
76### React.js / Preact / Inferno
77
78_The syntax for `React.js`, `Preact` and `Inferno` is the same_.
79
80This sample uses the class component syntax, but you can use hooks as well (if the library supports it).
81
82_Class Components_
83
84```typescript jsx
85import React from "react";
86import Particles from "react-tsparticles";
87import type { Engine } from "tsparticles-engine";
88import { loadSlim } from "tsparticles-slim";
89
90export class ParticlesContainer extends PureComponent<unknown> {
91 // this customizes the component tsParticles installation
92 customInit(engine: Engine) {
93 // this adds the bundle to tsParticles
94 loadSlim(engine);
95 }
96
97 render() {
98 const options = {
99 /* custom options */
100 };
101
102 return <Particles options={options} init={this.customInit} />;
103 }
104}
105```
106
107_Hooks / Functional Components_
108
109```typescript jsx
110import React, { useCallback } from "react";
111import Particles from "react-tsparticles";
112import type { Engine } from "tsparticles-engine";
113import { loadSlim } from "tsparticles-slim";
114
115export function ParticlesContainer(props: unknown) {
116 // this customizes the component tsParticles installation
117 const customInit = useCallback((engine: Engine) => {
118 // this adds the bundle to tsParticles
119 loadSlim(engine);
120 });
121
122 const options = {
123 /* custom options */
124 };
125
126 return <Particles options={options} init={this.customInit} />;
127}
128```
129
130### Vue (2.x and 3.x)
131
132_The syntax for `Vue.js 2.x` and `3.x` is the same_
133
134```vue
135<Particles id="tsparticles" :particlesInit="particlesInit" url="http://foo.bar/particles.json" />
136```
137
138```js
139function particlesInit(engine: Engine) {
140 loadSlim(engine);
141}
142```
143
144### Angular
145
146```html
147<ng-particles
148 [id]="id"
149 [options]="particlesOptions"
150 (particlesLoaded)="particlesLoaded($event)"
151 (particlesInit)="particlesInit($event)"
152></ng-particles>
153```
154
155```ts
156function particlesInit(engine: Engine): void {
157 loadSlim(engine);
158}
159```
160
161### Svelte
162
163```sveltehtml
164
165<Particles
166 id="tsparticles"
167 url="http://foo.bar/particles.json"
168 on:particlesInit="{onParticlesInit}"
169/>
170```
171
172```js
173let onParticlesInit = (engine) => {
174 loadSlim(engine);
175};
176```