1.2.0 • Published 5 years ago

@gregorydorrifourt/particles v1.2.0

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

@gregorydorrifourt/particles

Interactive particles background

Install

Using npm

npm install @gregorydorrifourt/particles

Using yarn

yarn add @gregorydorrifourt/particles

Hosting / CDN

File hosted at JSDelivr. Simply add this script before the closing body tag.

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@gregorydorrifourt/particles@latest/lib/particles.min.js"></script>

Usage

Create a <canvas> tag in your html. Default id is particles-background.

<canvas id="particles-background"></canvas>

Now in javascript, on window load, create a new instance of Particles class then call render().

<script type="text/javascript">
    window.onload = function(){
        var particles = new Particles();
        particles.render();
    }
</script>

Configuration

Particles.render takes a config object as parameter.

<script type="text/javascript">
    window.onload = function(){
        var config = {
            element: 'particles-background',
            contain: false,
            threshold: 150,
            particlesForScreenWidths: {
                small: 70,
                medium: 100,
                large: 150
            },
            fullscreen: false,
            addParticleOnClick: false,
            color: '#404040',
            bubble: true
        };
        var particles = new Particles(config);
        particles.render();
    }
</script>

You can use this online generator to test and create your own config :


AttributeTypeDescriptionDefault
addParticleOnClickBooleanAdd a new particle on clickfalse
bubbleBooleanParticles grow when mouse is approchingtrue
colorStringColor of particles and strokes#404040
containBooleanParticles stay within canvas boundaries. Affect density on small sizesfalse
elementStringId of canvas tagparticles-background
fullscreenBooleanCanvas element take all the screen and checks window.resize eventfalse
particlesForScreenWidthsObjectSet the number of particles for screens sizes{ small: 70, medium: 100, large: 150 }
thresholdNumberSet the maximum distance to draw a line between 2 dots. 0 => no lines150

Methods

FunctionParametersDescription
Particles.render()Config objectCreates background
Particles.reset()Config objectResets background with new config object
Particles.resume()Resume canvas animation
Particles.stop()Stop canvas animation
1.2.0

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago