A lightweight JavaScript library for creating particles

Overview

particles.js

A lightweight JavaScript library for creating particles.


Demo / Generator

particles.js generator

Configure, export, and share your particles.js configuration on CodePen:
http://vincentgarreau.com/particles.js/

CodePen demo:
http://codepen.io/VincentGarreau/pen/pnlso


Usage

Load particles.js and configure the particles:

index.html

<div id="particles-js"></div>

<script src="particles.js"></script>

app.js

/* particlesJS.load(@dom-id, @path-json, @callback (optional)); */
particlesJS.load('particles-js', 'assets/particles.json', function() {
  console.log('callback - particles.js config loaded');
});

particles.json

{
  "particles": {
    "number": {
      "value": 80,
      "density": {
        "enable": true,
        "value_area": 800
      }
    },
    "color": {
      "value": "#ffffff"
    },
    "shape": {
      "type": "circle",
      "stroke": {
        "width": 0,
        "color": "#000000"
      },
      "polygon": {
        "nb_sides": 5
      },
      "image": {
        "src": "img/github.svg",
        "width": 100,
        "height": 100
      }
    },
    "opacity": {
      "value": 0.5,
      "random": false,
      "anim": {
        "enable": false,
        "speed": 1,
        "opacity_min": 0.1,
        "sync": false
      }
    },
    "size": {
      "value": 10,
      "random": true,
      "anim": {
        "enable": false,
        "speed": 80,
        "size_min": 0.1,
        "sync": false
      }
    },
    "line_linked": {
      "enable": true,
      "distance": 300,
      "color": "#ffffff",
      "opacity": 0.4,
      "width": 2
    },
    "move": {
      "enable": true,
      "speed": 12,
      "direction": "none",
      "random": false,
      "straight": false,
      "out_mode": "out",
      "bounce": false,
      "attract": {
        "enable": false,
        "rotateX": 600,
        "rotateY": 1200
      }
    }
  },
  "interactivity": {
    "detect_on": "canvas",
    "events": {
      "onhover": {
        "enable": false,
        "mode": "repulse"
      },
      "onclick": {
        "enable": true,
        "mode": "push"
      },
      "resize": true
    },
    "modes": {
      "grab": {
        "distance": 800,
        "line_linked": {
          "opacity": 1
        }
      },
      "bubble": {
        "distance": 800,
        "size": 80,
        "duration": 2,
        "opacity": 0.8,
        "speed": 3
      },
      "repulse": {
        "distance": 400,
        "duration": 0.4
      },
      "push": {
        "particles_nb": 4
      },
      "remove": {
        "particles_nb": 2
      }
    }
  },
  "retina_detect": true
}

Options

key option type / notes example
particles.number.value number 40
particles.number.density.enable boolean true / false
particles.number.density.value_area number 800
particles.color.value HEX (string)
RGB (object)
HSL (object)
array selection (HEX)
random (string)
"#b61924"
{r:182, g:25, b:36}
{h:356, s:76, l:41}
["#b61924", "#333333", "999999"]
"random"
particles.shape.type string
array selection
"circle"
"edge"
"triangle"
"polygon"
"star"
"image"
["circle", "triangle", "image"]
particles.shape.stroke.width number 2
particles.shape.stroke.color HEX (string) "#222222"
particles.shape.polygon.nb_slides number 5
particles.shape.image.src path link
svg / png / gif / jpg
"assets/img/yop.svg"
"http://mywebsite.com/assets/img/yop.png"
particles.shape.image.width number
(for aspect ratio)
100
particles.shape.image.height number
(for aspect ratio)
100
particles.opacity.value number (0 to 1) 0.75
particles.opacity.random boolean true / false
particles.opacity.anim.enable boolean true / false
particles.opacity.anim.speed number 3
particles.opacity.anim.opacity_min number (0 to 1) 0.25
particles.opacity.anim.sync boolean true / false
particles.size.value number 20
particles.size.random boolean true / false
particles.size.anim.enable boolean true / false
particles.size.anim.speed number 3
particles.size.anim.size_min number 0.25
particles.size.anim.sync boolean true / false
particles.line_linked.enable boolean true / false
particles.line_linked.distance number 150
particles.line_linked.color HEX (string) #ffffff
particles.line_linked.opacity number (0 to 1) 0.5
particles.line_linked.width number 1.5
particles.move.enable boolean true / false
particles.move.speed number 4
particles.move.direction string "none"
"top"
"top-right"
"right"
"bottom-right"
"bottom"
"bottom-left"
"left"
"top-left"
particles.move.random boolean true / false
particles.move.straight boolean true / false
particles.move.out_mode string
(out of canvas)
"out"
"bounce"
particles.move.bounce boolean
(between particles)
true / false
particles.move.attract.enable boolean true / false
particles.move.attract.rotateX number 3000
particles.move.attract.rotateY number 1500
interactivity.detect_on string "canvas", "window"
interactivity.events.onhover.enable boolean true / false
interactivity.events.onhover.mode string
array selection
"grab"
"bubble"
"repulse"
["grab", "bubble"]
interactivity.events.onclick.enable boolean true / false
interactivity.events.onclick.mode string
array selection
"push"
"remove"
"bubble"
"repulse"
["push", "repulse"]
interactivity.events.resize boolean true / false
interactivity.events.modes.grab.distance number 100
interactivity.events.modes.grab.line_linked.opacity number (0 to 1) 0.75
interactivity.events.modes.bubble.distance number 100
interactivity.events.modes.bubble.size number 40
interactivity.events.modes.bubble.duration number
(second)
0.4
interactivity.events.modes.repulse.distance number 200
interactivity.events.modes.repulse.duration number
(second)
1.2
interactivity.events.modes.push.particles_nb number 4
interactivity.events.modes.push.particles_nb number 4
retina_detect boolean true / false

Packages install

npm

https://www.npmjs.com/package/particles.js

npm install particles.js
Bower
bower install particles.js --save
Rails Assets
gem 'rails-assets-particles.js'
Meteor

https://atmospherejs.com/newswim/particles

meteor add newswim:particles

Hosting / CDN

Please use this host or your own to load particles.js on your projects

http://www.jsdelivr.com/#!particles.js

Comments
  • Particle not at the good place

    Particle not at the good place

    Hi,

    I am trying to make Particle JS work as a background. As you can see on my website, the body as the attribute particles but, the particles are only after the content. It dosen't follow the order. Here is the config:

    particlesJS("particles-js", {
        particles: {
            number: {
                value: 80,
                density: {
                    enable: !0,
                    value_area: 800
                }
            },
            color: {
                value: "#ffffff"
            },
            shape: {
                type: "circle",
                stroke: {
                    width: 0,
                    color: "#000000"
                },
                polygon: {
                    nb_sides: 5
                },
                image: {
                    src: "img/github.svg",
                    width: 100,
                    height: 100
                }
            },
            opacity: {
                value: .5,
                random: !1,
                anim: {
                    enable: !1,
                    speed: 1,
                    opacity_min: .1,
                    sync: !1
                }
            },
            size: {
                value: 3,
                random: !0,
                anim: {
                    enable: !1,
                    speed: 40,
                    size_min: .1,
                    sync: !1
                }
            },
            line_linked: {
                enable: !0,
                distance: 150,
                color: "#ffffff",
                opacity: .4,
                width: 1
            },
            move: {
                enable: !0,
                speed: 6,
                direction: "none",
                random: !1,
                straight: !1,
                out_mode: "out",
                bounce: !1,
                attract: {
                    enable: !1,
                    rotateX: 600,
                    rotateY: 1200
                }
            }
        },
        interactivity: {
            detect_on: "canvas",
            events: {
                onhover: {
                    enable: !0,
                    mode: "grab"
                },
                onclick: {
                    enable: !0,
                    mode: "push"
                },
                resize: !0
            },
            modes: {
                grab: {
                    distance: 140,
                    line_linked: {
                        opacity: 1
                    }
                },
                bubble: {
                    distance: 400,
                    size: 40,
                    duration: 2,
                    opacity: 8,
                    speed: 3
                },
                repulse: {
                    distance: 200,
                    duration: .4
                },
                push: {
                    particles_nb: 4
                },
                remove: {
                    particles_nb: 2
                }
            }
        },
        retina_detect: !0
    });
    

    Thanks!

    opened by FelixINX 14
  • particlesJS not defined

    particlesJS not defined

    Uncaught ReferenceError: particlesJS is not defined
        at (index):911
    

    This is my Code:

    <div id="particles-js"></div>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.0.2/particles.min.js"></script>
    
    <script type="text/javascript">
    /* particlesJS.load(@dom-id, @path-json, @callback (optional)); */
    particlesJS.load('particles-js', 'bilder/particlesjs-config.json', function() {
      console.log('callback - particles.js config loaded');
    });
    </script>
    

    whats wrong?

    opened by TheSoulrester 12
  • Not able to create multiple instances of particles-js

    Not able to create multiple instances of particles-js

    I tried Creating Multiple calls to particleJS function in order to run multiple instances of particleJS in certain divs on my HTML page. but by default it only redenrs the first div which is called and ignores the rest. Is there any way we can fix this?

    I've Already Referred to #33 , #183 and #302 but still the query remains unsolved. Please Help with the same and provide a robust solution for this.

    opened by dwij2812 11
  • Particles.js behind some pre-existing HTML

    Particles.js behind some pre-existing HTML

    Hey there! I was wondering how I could put P.js behind my existing HTML. My HTML is https://greemdotcs.github.io - and the source for my HTML is on my repo for that website, https://github.com/greemdotcs/greemdotcs.github.io/ - Thanks!

    opened by GreemDev 9
  • Multiple particlesJS

    Multiple particlesJS

    Hi, I'm trying to apply your plugin on multiple IDs, works fine for drawing it, but only the last created canvas is interactive/animated. Do you have any solution?

    Thanks :)

    feature / idea 
    opened by Spharian 7
  • Changing the size and color of each shape

    Changing the size and color of each shape

    Maybe it could be added? this is the options that I would provide:

    • increase/decrease (size)
      • active / inactive
      • for each particle differently
      • for all particles the same:
        • increase
        • decrease
        • random (increase || decrease)
      • duration
    • change of color:
      • array of colors for example [#fee, #fcc, #a00, #fee]
      • the easeIn || easeInOut option
      • speed

    And one more thing, ... automate the min version with grunt...

    feature / idea 
    opened by MHM5000 7
  • Uncaught TypeError: (0 , _particlesMin2.default) is not a function

    Uncaught TypeError: (0 , _particlesMin2.default) is not a function

    I try to integrate with webpack to put my page but i having this error any idea why ? if i give direct link it's working. but with webpack + babel it's not.

    opened by Necmttn 6
  • How to decrease density of particles on mobile screen?

    How to decrease density of particles on mobile screen?

    Hey Vincent Thanks for this :) I am having a little problem as Your online preview " http://vincentgarreau.com/particles.js/ " looks so smooth on all screens. When I am running file locally(in small screens) i get the view as particles js

    The particles are condensing too much on the sides of window when i resize the window Could you please help me where I am missing out to get a smooth view like yours?

    feature / idea dev branch 
    opened by rahulsimpact 5
  • Feature: fadein

    Feature: fadein

    Hi, Vincent.

    Thanks very much for this great project.

    Is there any way to specify particles to fade in one by one or in step ones, or fade in by opacity.

    feature / idea dev branch 
    opened by mudox 5
  • Particles and React

    Particles and React

    Let me start by saying I love this library! I am trying to get this to work with React. I'm calling particlesJS.load('particles-js', '../assets/particles.config.json', function() { console.log(callback - particles.js config loaded'); }); inside the componentDidMount ion my Main container, but am getting this error _particles2.default.load is not a function in my console. The package is downloaded and imported in on my file.

    In my HTML file, I've given the body an id of particles-js (so as not to conflict with the div id of app for React in the body)

    I would love any suggestions! Thanks so much :)

    opened by NoelAnnParisi 4
  • Mouse Interaction Offset on Smaller Canvas

    Mouse Interaction Offset on Smaller Canvas

    Hello,

    Firstly let me apologise - I don't have any experience using Canvas and am still getting to grips with it so sorry if this is a very obvious question.

    I'm trying to use the particle animation within a div that is part of the sidebar to my website however it seems when doing so the mouse interaction is not as accurate. I've narrowed down the issue and found it's due to the fact that there is a div on top of the div containing particle-js - if I remove the top div the mouse interaction is accurate but it seems with it still in the canvas is offsetting the interaction animation by the height of the top div.

    Site URL - http://www.nrly.co

    I was hoping you might be able to give me some guidance on this issue?

    Many, many thanks in advance!

    opened by nrly 4
  • Fix for strict mode aka make it work in modules without breaking normal mode

    Fix for strict mode aka make it work in modules without breaking normal mode

    Swapped out arguments.callee for a simple recursive call, so the script can run in strict mode ie: inside modules but it doesn't break running outside a module.

    Usage inside a module:

    import "https://code.jquery.com/jquery-3.2.1.js";
    import "<path>/particles.js"
    
    window.particlesJS("particle-canvas-green", {
                particles: {
                    number: {
                        value: 100,
                        ...
    });
    

    Also added canvasResize and return the pJS object, so canvases can be resized explicitly. This can allow elements that are initially not displayed to host particles and then once they are displayed, we can call this and have the particles work as expected rather than occupy a 0x0 canvas.

    import "https://code.jquery.com/jquery-3.2.1.js";
    import "<path>/particles.js"
    
    const particle_js_green = window.particlesJS("transition-particle-canvas-green", {
                particles: {
                    number: {
                        value: 100,
                        ...
    });
    
    // Then on event
    particle_js_green.canvasResize();
    
    opened by Dark-Bob 2
  • Push particles based on variable change in a seperate function

    Push particles based on variable change in a seperate function

    Hi there, not expecting much help from here but I'll give it a shot anyway:

    I'm using WebSockets to retrieve a number that changes every now and then in my project. I have added it to Particles.js and assigned a variable to the changing number.

    Next, I can use that Variable to set how many particles are pushed on click. But this variable only updates once at the beginning and then doesn't register the changes coming from my WebSockets.

    I was wondering if there is a way, to push new particles based on the number I am getting from my WebSockets instead of having to click.

    So in Theory, my particles.js receives data via my WebSocket connection, I store this data as an int, and depending on the int new particles are added or reduced from the canvas. Everytime new data comes via WebSocket this process is repeated.

    Any hints or Ideas how I could get something like this done ?

    opened by odonald 3
  • Can't interact with the page content - Elementor

    Can't interact with the page content - Elementor

    Hello, I'm using particles in elementor When I add the code to the section and view it, I can't interact with anything in the section I add particles to it. The section has buttons, I can't click on them or select the text. Can someone please tell me where the issue is?

    opened by AliAhmad997 1
Releases(2.0.0)
  • 2.0.0(May 9, 2015)

    New features

    • New calling function: load json config • Support multiple particles.js on a same page • Custom shape image (svg, png, jpg...) • Custom shape polygon (include star, with custom number sides) • Stroke shape • Support RGB and HSL color • Array selection for color_random (HEX values) • Opacity random particles • Animation size / opacity particles • Bounce effect (out mode + between particles) • Custom moving direction / straight mode • New « bubble » mode interaction (hover + click) • New « repulse » mode interaction (hover + click) • Support multi modes on hover / click event

    Fixes / Optimizations

    • Better performance (on Firefox, line linked process…) • Distance / opacity line_linked • Improve merge paramaters • Opacity on color random / array particles • Edge shape position • Equilateral triangle shape • Add packages : npm, Rails Assets, Meteor • Refresh canvas on click event / anim disabled • Rounded linked line • Line linked opacity on hover event • Grab mode fixes

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(May 9, 2015)

    New features

    • density_auto on resize event (number of particles depending on canvas area)

    pJS.interactivity.onresize = {
      density_auto: boolean,
      density_area: number // number of particles = pJS.particles.nb * (canvas width *  canvas height / 1000) / density_area
    }
    

    • modes on resize event

    pJS.interactivity.onresize.mode = 'out' or 'bounce'
    

    • color random particles

    pJS.particles.color_random = boolean
    

    • opacity animation particles

    pJS.particles.opacity.anim = {
      enable: boolean,
      speed: number,
      opacity_min: number,
      sync: boolean
    }
    

    Fixes / Optimizations

    • destroy function: fix console error (pJS) • pushParticles / removeParticles functions • resize window listener

    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Nov 19, 2014)

  • 1.0.2(Nov 16, 2014)

  • 1.0.1(Nov 15, 2014)

  • 1.0.0(Nov 12, 2014)

Owner
Vincent Garreau
Co-founder & Lead front-end livestorm.co
Vincent Garreau
React particles animation background component

particles-bg React component for particles backgrounds This project refers to the source code of the Proton official website, I packaged it into a com

lindelof 561 Dec 24, 2022
🐿 Super easy and lightweight(<3kb) JavaScript animation library

Overview AniX - A super easy and lightweight javascript animation library. AniX is a lightweight and easy-to-use animation library with excellent perf

anonymous namespace 256 Sep 19, 2022
Slickscroll - A Lightweight JavaScript library for quick and painless momentum & parallax scrolling effects.

Slickscroll is a JavaScript library that makes momentum & parallax scrolling quick and painless View Demo: slickscroll.musabhassan.com Momentum Scroll

Musab Hassan 33 Dec 28, 2022
Nebula is a lightweight (1kb compressed) JavaScript library that creates beautiful universe animations.

Nebula is a lightweight JavaScript library for creating beautiful universe animations. Including configurable Stars, Nebulas, Comets, Planets and Suns. Compatible with SSR

Florian DE LA COMBLE 34 Nov 25, 2022
fakeLoader.js is a lightweight jQuery plugin that helps you create an animated spinner with a fullscreen loading mask to simulate the page preloading effect.

What is fakeLoader.js fakeLoader.js is a lightweight jQuery plugin that helps you create an animated spinner with a fullscreen loading mask to simulat

João Pereira 721 Dec 6, 2022
Lightweight, simple to use jQuery plugin to animate SVG paths

jQuery DrawSVG This plugin uses the jQuery built-in animation engine to transition the stroke on every <path> inside the selected <svg> element, using

Leonardo Santos 762 Dec 20, 2022
GreenSock's GSAP JavaScript animation library (including Draggable).

GSAP (GreenSock Animation Platform) Professional-grade animation for the modern web GSAP is a robust JavaScript toolset that turns developers into ani

GreenSock 15.5k Jan 8, 2023
Javascript library to create physics-based animations

Dynamics.js Dynamics.js is a JavaScript library to create physics-based animations To see some demos, check out dynamicsjs.com. Usage Download: GitHub

Michael Villar 7.5k Jan 6, 2023
Javascript and SVG odometer effect library with motion blur

SVG library for transitioning numbers with motion blur JavaScript odometer or slot machine effect library for smoothly transitioning numbers with moti

Mike Skowronek 793 Dec 27, 2022
Responsive, interactive and more accessible HTML5 canvas elements. Scrawl-canvas is a JavaScript library designed to make using the HTML5 canvas element a bit easier, and a bit more fun!

Scrawl-canvas Library Version: 8.5.2 - 11 Mar 2021 Scrawl-canvas website: scrawl-v8.rikweb.org.uk. Do you want to contribute? I've been developing thi

Rik Roots 227 Dec 31, 2022
GreenSock's GSAP JavaScript animation library (including Draggable).

GSAP (GreenSock Animation Platform) Professional-grade animation for the modern web GSAP is a robust JavaScript toolset that turns developers into ani

GreenSock 15.4k Jan 5, 2023
simple JavaScript library to animate texts

Animated Texts Hi, this library is a simple javascript text animator Properties force type: number default: 300 start_delay_time type: number default:

Cristóvão 4 Jan 11, 2022
Animate Plus is a JavaScript animation library focusing on performance and authoring flexibility

Animate Plus Animate Plus is a JavaScript animation library focusing on performance and authoring flexibility. It aims to deliver a steady 60 FPS and

Benjamin De Cock 5.9k Jan 2, 2023
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

Animate.css If you need the old docs - v3.x.x and under - you can find it here. Just-add-water CSS animation Installation Install with npm: npm instal

Animate.css 76.7k Dec 30, 2022
Animation library that mimics CSS keyframes when scrolling.

Why Motus ? Motus allows developers to create beatuful animations that simulate css keyframes and are applied when the user scrolls. Features Node & B

Alexandru Cambose 580 Dec 30, 2022
:dizzy: TransitionEnd is an agnostic and cross-browser library to work with transitionend event.

TransitionEnd TransitionEnd is an agnostic and cross-browser library to work with event transitionend. Browser Support 1.0+ ✔ 4.0+ ✔ 10+ ✔ 10.5 ✔ 3.2+

Evandro Leopoldino Gonçalves 95 Dec 21, 2022
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

Animate.css If you need the old docs - v3.x.x and under - you can find it here. Just-add-water CSS animation Installation Install with npm: npm instal

Animate.css 76.7k Jan 4, 2023
A library to add a virtual Trackball to your DOM

Trackball.js - 3D Trackballs for your Website Trackball.js is a small JavaScript library on top of Quaternion.js to enable free 3D rotation of element

Robert Eisele 34 Nov 27, 2022
Theatre.js is an animation library for high-fidelity motion graphics.

Theatre.js is an animation library for high-fidelity motion graphics. It is designed to help you express detailed animation, enabling you to create intricate movement, and convey nuance.

Aria 8.6k Jan 3, 2023