There are a large number of tiny particles moving around and interacting with each other—or interacting with you—with a unique attraction. Particles.js will be very useful if you need to deal with large amounts of particles. As the name implies, it is a JavaScript library that helps you create particle systems. Plus, it's lightweight, easy to use, and gives you plenty of control.
This tutorial will cover all the features of this library and help you get started. This tutorial is the first part of this series and covers only the basics.
Installation and use
First, you need to host the library. You can upload it to your own server or use jsdeliver CDN like I did.
<code><br></code>
You also need to create a DOM element where Particles.js will create particles. Give it a circle that is easy to identify. At this point, your file should look like this:
<code>{<br> "particles": {<br> "number": {<br> "value": 100<br> },<br> "shape": {<br> "type": "circle"<br> }<br> },<br> "interactivity": {<br><br> }<br>}<br></code>
I use a value of 10 to set the size of the snowflake. Since the snowflakes vary in size, I set random
to true
. This way, the size of the snowflake can vary between the zero and maximum limits we specify. To disable or delete all lines connecting these particles, you can set line_linked
's enable
to false
.
To move particles, you must set the enable
attribute to true
. Without any other settings, the particles will move in a mess, just like they are in space. You can set the orientation of these particles using string values (such as "bottom"
). Even if the overall motion of particles is downward, they still need to move slightly randomly to look natural. This can be done by setting straight
to false
. At this point, snowflakes.json
will contain the following code:
<code>{<br> "particles": {<br> "number": {<br> "value": 100<br> },<br> "shape": {<br> "type": "circle"<br> },<br> "size": {<br> "value": 10,<br> "random": true<br> },<br> "line_linked": {<br> "enable": false<br> },<br> "move": {<br> "enable": true,<br> "speed": 2,<br> "direction": "bottom",<br> "straight": false<br> }<br> },<br> "interactivity": {<br><br> }<br>}<br></code>
Use the above JSON code, you will get the following results:
Change interactive behavior
If you hover over the demo above, you will notice that the lines still exist, but only temporarily display during the hover. To delete them completely, you can set the onhover
property of the enable
event to false
. Try clicking on the demo above and you will notice that each click generates four particles. This is the default behavior. You can also change the number of particles using the push
attribute under particles_nb
. In this case, I have set this number to 12.
You can also use the detect_on
option to determine whether to detect events on a window or on a canvas.
The following is the complete code of the JSON file:
<code><br></code>
As you can see, I don't have to enable the onclick
event specifically. It is enabled by default. Similarly, I can delete other options such as interactivity
and "detect_on": "canvas"
under move
. I keep them so that beginners won't be confused about questions like why particles don't move in a straight line. "straight": false"
You can try different values to modify the snowflakes in the CodePen above. Just click the
JS tab to edit JSON.
Final ThoughtsParticles.js is easy to get started. If you have never used a particle system before, this library will help you get started right away. This tutorial is just a basic introduction to the library. In the next two tutorials in this series, I will cover all aspects of the library in more detail.
If you have any questions about this tutorial, please let me know in the forum.
The above is the detailed content of Particles.js: Introduction. For more information, please follow other related articles on the PHP Chinese website!

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more.

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1
Easy-to-use and free code editor
