tsparticles

tsParticles - Particles.js on steroids

Github stars Tracking Chart

tsParticles - TypeScript Particles

A lightweight TypeScript library for creating particles. Dependency free (*) and browser ready!

Particles.js converted in TypeScript, dependency free (*), improved with new cool ? features and various bugs fixed and it's currently under development!

jsDelivr Cdnjs npmjs npm, master, staging, dev, -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, Master Build Status, Staging Build Status, Dev Build Status, CodeFactor Codacy Badge Codacy Badge Sauce Test Status

Slack tsParticles Product Hunt

Do you want to use it on your website?

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.

You'll find the instructions below, with all the links you need, and don't be scared by TypeScript, it's just the source language.

The output files are just JavaScript. ?

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.

If you are still interested some lines below there are some instructions for migrating from the old particles.js library.

jQuery

npm npm

If you want to use tsParticles with jQuery checkout this repository

VueJS

npm npm

If you want to use tsParticles with VueJS checkout this repository

ReactJS

npm npm

If you want to use tsParticles with ReactJS checkout this repository

3rd Party

A 3rd-party component is available too, read more here

Preact

npm npm

If you want to use tsParticles with Preact checkout this repository

Angular CLI

npm npm

If you want to use tsParticles with Angular CLI (actually v9) checkout this repository

Want to see it in action and try it?

I've created a tsParticles collection on CodePen ? or you can checkout my profile

Otherwise there's the demo page link below. Just click/tap the Coronavirus below, don't be scared. It's safe ?.

tsParticles demo

Want to see ever more demos? Clone the repository on your computer and follow these instructions

npm install && npm start

Boom! ? http://localhost:3000 and you can checkout other demos.

If you are brave enough you can switch to the dev branch for trying the features under development.

Dependencies

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.


Migrating from Particles.js

tsParticles library is fully compatible with the particles.js configuration.

Seriously, you just need to change the script source et-voilà, you're ready ?!

You can read more here

Want to know 5 reasons to do the switch? Read here

Below you can find all the information you need to install tsParticles and its new syntax.


Plugins/Customizations

tsParticles now supports some customizations ?.

NOW YOU CAN CREATE YOUR OWN PLUGINS

Read more here...


API Docs

Documentation and Development references here ?


Library installation

Hosting / CDN

Please use this hosts or your own to load tsParticles on your projects

jsDelivr

jsDelivr

cdnjs

Cdnjs

unpkg

https://unpkg.com/tsparticles/


npm

npmjs npmjs

npm install tsparticles

yarn

yarn add tsparticles

Import and require

Starting from version 1.12.11 import and require can be used to import tsParticles.

Now you can write something like this

const tsParticles = require("tsparticles");

// or

import { tsParticles } from "tsparticles";

the imported tsParticles is the same instance you have including the script.


NuGet

Nuget


Usage

Load tsParticles and configure the particles:

tsParticles demo

index.html

<div id="tsparticles"></div>

<script src="tsparticles.min.js"></script>

app.js

// @path-json can be an object or an array, the first will be loaded directly, the object from the array will be random selected
/* tsParticles.loadJSON(@dom-id, @path-json, @callback (optional)); */
tsParticles
  .loadJSON("tsparticles", "presets/default.json")
  .then((container) => {
    console.log("callback - tsparticles config loaded");
  })
  .catch((error) => {
    console.error(error);
  });

//or

/* tsParticles.load(@dom-id, @options); */
tsParticles.load("tsparticles", {
  /* options here */
});

//or

/* tsParticles.loadFromArray(@dom-id, @options, @index (optional)); */
tsParticles.loadFromArray("tsparticles", [
  {
    /* options here */
  },
  {
    /* other options here */
  },
]); //random object
tsParticles.loadFromArray(
  "tsparticles",
  [
    {
      /* options here */
    },
    {
      /* other options here */
    },
  ],
  1
); //the second one
// Important! If the index is not in range 0...array.length, the index will be ignored.

// after initialization this can be used.

/* tsParticles.setOnClickHandler(@callback); */
/* this will be fired from all particles loaded */
tsParticles.setOnClickHandler((e) => {
  /* custom on click handler */
});

// now you can control the animations too, it's possible to pause and resume the animations
// these methods don't change the config so you're safe with all your configurations
// domItem(0) returns the first tsParticles instance loaded in the dom
const particles = tsParticles.domItem(0);
// play will start the animations, if the move is not enabled it won't enable it, it just updates the frame
particles.play();
// pause will stop the animations
particles.pause();

Import and require

Starting from version 1.12.7 import and require can be used to import tsParticles.

Now you can write something like this

const tsParticles = require("tsparticles");

// or

import { tsParticles } from "tsparticles";

React.js

tsParticles ❤️ react-particles-js

Starting from react-particles-js version 3.0.0 it has added tsParticles as a dependency.

You can follow the instructions here to install react-particles-js and use all the configurations described in this readme to configure the particles.


Demo / Generator

https://particles.matteobruni.it/

Particles demo


Characters as particles

Particles chars demo


Mouse hover connections

Particles mouse connections demo


Polygon mask

tsParticles Polygon Mask demo


Animated stars

Particles NASA demo


Nyan cat flying on scrolling stars

Particles Nyan Cat demo


Snow particles

tsParticles Snow demo


Background Mask particles

tsParticles Background Mask demo


COVID-19 SARS-CoV-2 particles

tsParticles COVID-19 demo

Don't click! DON'T CLICK! OH NO IT'S SPREADING!!!!


particles.json

You can find a sample config here ?


Options

You can find all options available here ?


Stargazers over time

Stargazers over time


Huge thanks to JetBrains for the 2020 Open Source License!

JetBrains WebStorm is used to maintain this project.

Huge thanks to SauceLabs for the Open Source License!

Main metrics

Overview
Name With Ownertsparticles/tsparticles
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2020-02-05 18:00:01
Pushed At2025-04-20 02:50:07
Last Commit At
Release Count11411
Last Release Namev3.8.1 (Posted on 2025-01-31 09:01:29)
First Release Name1.3.1 (Posted on )
用户参与
Stargazers Count8.2k
Watchers Count118
Fork Count892
Commits Count14k
Has Issues Enabled
Issues Count440
Issue Open Count13
Pull Requests Count4327
Pull Requests Open Count10
Pull Requests Close Count419
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private