Lightweight TypeScript Library For Interactive Particles Javascript | tsparticles

Particles JS is a lightweight TypeScript library for creating particles. tsparticles is an upgraded and continued model of the Particles.js library to create particles in a sublime method.

tsParticles – Easily create highly customizable JavaScript particle effects, snippet explosions, and fireworks animations and use them as animated backgrounds for your website. Ready-to-use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot, and Web components.

Key features options:

  • 16 pre-defined presets (JSON).
  • Circle, line, edge, triangle, polygon, and star shapes.
  • Or utilizing a customized picture.
  • More transfer outmodes bounce, bounce-vertical, and bounce-horizontal.
  • Bugs mounted.
  • And extra customization choices.

Must Read: A Concise, Lightweight, and Efficient Canvas Library for Cool Particle Effects | JParticles

How to make use of it:

1. Install & Download:

# NPM
$ npm install tsparticles --save

2. Load the tsparticles library from a CDN.

<script src="https://cdn.jsdelivr.net/npm/tsparticles/dist/tsparticles.min.js"></script>

3. Create a container the place you need to render the particles.

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

4. Initialize the tsparticles and cargo a preset of your alternative as follows:

tsParticles.loadJSON("tsparticles", "presets/bubble.json").then((container) => {
  console.log("callback");
}).catch((error) => {
  console.error(error);
});

5. You may create customized particles bypassing the next choices:

tsParticles.load("tsparticles", { 
  /**
   * Background options, these background options will be used to the canvas element, they are all CSS properties
   */
  background: {

    /**
     * The background color used by the canvas element, string or object
     * For Example: '#ffffff', 'rgb(255, 255, 255)', 'hsl(0, 100%, 100%)', 'random'
     */
    color: string or object,

    /**
     * The background opacity
     */
    opacity: number,

    /**
     * The background image used by the canvas element, its value will be used to set CSS property background-image
     */
    image: string,

    /**
     * The background position, it's used by the CSS property background-position
     */
    position: string,

    /**
     * The background position, it's used by the CSS property background-repeat
     */
    repeat: string,

    /**
     * The background size, it's used by the CSS property background-size
     */
    size: string,

  },

  /**
   * Background Mask options, what's behind the canvas will become hidden and particles will uncover it
   */
  backgroundMask: {

    /**
     * The color to use as a canvas background to cover
     */
    cover: {
      color: string or object,
      opacity: 0-1,
    },

    /**
     * This settings enables the cover and the particles behavior as unveiling elements
     */
    enable: boolean,

  },

  /**
   * Enables the retina detection, if disabled the ratio used by canvas will be always 1 and not the device setting.
   */
  detectRetina: boolean,

  /**
   * The Frame Per Second limit applied to all particles animations.
   * @deprecated use the new fpsLimit instead
   */
  fps_limit: number,

  /**
   * The F(rame)P(er)S(econd) limit applied to all particles animations.
   */
  fpsLimit: number,

  /**
   * The infection options
   */
  infection: {

    /**
     * if the infection can be cured, bringing back the particle to its normal state
    */
    cure: boolean,

    /**
     * the "symptoms" delay, after how many seconds the infected particle change its state
    */
    delay: 1,
    enable: boolean,

    /**
     * how many particles are infected at startup
    */
    infections: 1.
    stages: array   

  },

  /**
   * The particles interaction options
   */
  interactivity: {
    "detect_on": "canvas", // "canvas", "window","parent"
    "events": {
      "onhover": {
        "enable": false,
        /* 
          "grab"
          "bubble"
          "repulse"
          "connect"
          ["grab", "bubble"]
        */
        "mode": "repulse"
      },
      "onclick": {
        "enable": true,
        /*
          "push"
          "remove"
          "bubble"
          "repulse"
          "pause"
          "emitter"
          "absorber"
        */
        "mode": "push"
      },
      "onDiv": {
        "enable": true,
        /*
          "bubble"
          "repulse"
        */
        "mode": "push",
        /*
          "circle"
          "rectangle"
        */
        "type": "rectangle",
        "ids": string or array
      },
      "resize": true
    },
    "modes": {
      "connect": {
        "distance": 400,
        "radius": 60,
        "lineLinked": {
          opacity: 0-1,
        }
      },
      "grab": {
        "distance": 400,
        "lineLinked": {
          "opacity": 0-1,
        }
      },
      "bubble": {
        "distance": 400,
        "duration": 2,
        "size": 40,
      },
      "push": {
        "quantity": 4
      },
      "remove": {
        "quantity": 4
      },
      "repulse": {
        "distance": 200,
        "duration": 0.4
      },
      "emitter": object / array,
      "absorber": object / array
    }
  },

  /**
   * The particles options
   */
  particles: {
    "color": {
      "value": "#ffffff"
    },
    "links": {
      "distance": 150,
      "id": string,
      "color": string or object,
      "opacity": 0-1,
      "width": 1.5
    },
    "move": {
      "enable": true,
      "speed": 12,
      /*
        "none"
        "top"
        "top-right"
        "right"
        "bottom-right"
        "bottom"
        "bottom-left"
        "left"
        "top-left"
      */
      "direction": "none",
      "random": false,
      "straight": false,
      /*
        "out"
        "destroy"
        "bounce"
        "bounce-vertical"
        "bounce-horizontal"
      */
      "out_mode": "out",
      "collisions": false,
      "trail": {
        "enable": true,
        "length": 10,
        "fillColor": object
      }
      "attract": {
        "enable": false,
        "rotateX": 600,
        "rotateY": 1200
      }
    }
    "rotate": {
      "value": 80,
      "random": true,
      "direction": "clockwise or counterclockwise"
      "animation": {
        "enable": true,
        "speed": 5,
        "sync": true
      }
    },
    "number": {
      "value": 80,
      "limit": 200,
      "density": {
        "enable": true,
        "area": 800
      }
    },
    "opacity": {
      "value": 0.5,
      "random": {
        "enable": true,
        "minimumValue": 10
      },
      "animation": {
        "enable": false,
        "speed": 1,
        "minimumValue": 0.1,
        "sync": false
      }
    },
    "shape": {
      /* "circle"
      "line"
      "edge"
      "triangle"
      "polygon"
      "star"
      "image"
      ["circle", "triangle", "image"]
      */
      "type": "circle", 
      "particles": {
        // Particles options here
      },
      "fill": true / false,
      "close": true / false,
      "image": {
        "src": "img/github.svg",
        "width": 100,
        "height": 100,
        "replaceColor": false
      },
      polygon: {
        sides: 5
      },
      star: {
        sides: 5, 
        inset: 2
      },
      character: {
        value: "*",
        font: "Verdana",
        style: "",
        weight: ""
      }
    },
    "size": {
      "value": 10,
      "random": {
        "enable": true,
        "minimumValue": 10
      },
      "animation": {
        "enable": false,
        "speed": 80,
        "minimumValue": 0.1,
        "sync": false
      }
    },
    "stroke": {
      "width": 2,
      "color": object
    },
    "twinkle": {
      "particles": {
        "enable": false,
        "color": object,
        "frequency": 0-1,
        "opacity": 0-1,
      },
      "lines": object
    },
  },

  /**
   * Enables or disabled the animation on window blur
   */
  pauseOnBlur: boolean,

  /**
   * This property will be used to add specified presets to the options
   */
  preset: string | string[],

});

6. Load particles from an array.

tsParticles.loadFromArray("tsparticles", [{ /* options here */ }, { /* other options here */ }]);

7. Fire an event when all particles are loaded.

tsParticles.setOnClickHandler((e) => { 
  /* custom on click handler */ 
});

8. Control the animations.

const particles = tsParticles.domItem(0);
// play the animations
particles.play();
// pause the animations
particles.pause();

Mst Read: Performant Particles tsParticles or Particles.js System In JavaScript | perParticles.js

Presets

There are some ready-to-use presets in this repository, and they also have a package file that contains everything needed to run.

Big circles

This preset loads large colored circles moving upwards on a white background.

bubbles

This preset loads colored bubbles coming from the bottom of the screen on a white background.

Colored paper clips – Confetti

This preset loads white and red confetti shots from the center of the screen against a transparent background.

Fire

This preset load’s dull reds on a black background with colored particles like fire sparks and ash.

Firefly

This preset loads a mouse track made of tiny, faint particles like tiny fireflies.

Fireworks

This preset has a beautiful fireworks effect.

Fountain

Links

Sea anemones

Snow

Stars

Triangles

Read More – 

Object Detection in Viewport and Smooth Scrolling With Parallax Effects | Locomotive Scroll
A Lightweight and Powerful Particle Animation Javascript Library | Proton.js


See Demo And Download

Official Website(matteobruni): Click Here

This superior jQuery/javascript plugin is developed by matteobruni. For extra Advanced Usage, please go to the official website.

Share