tsParticles - Easily create highly customizable JavaScript particles effects, confetti 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.
tsParticles - TypeScript Particles
A lightweight TypeScript library for creating particles. Dependency free (*), browser ready and compatible with
React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Riot.js, Solid.js, and Web Components
Here's a small demo of the effect, if you remove the background options it will be transparent so you can put in your website without changing anything.
Configuration
This is one of the easiest configuration for a nice snow effect. It's not interacting with the mouse events, but it can be achieved easily.
file with comments, it can be used only in .js files
{// The background color is for making the particles visible since they're white. Remove this section if not needed"background":{"color":"#000000"},// The particles options"particles":{// The color of the particles/snowflakes"color":{"value":"#fff"},// Move the snow flakes to bottom for a realistic effect, "out" in outModes is for making them reappear on top once exited at the bottom of the page, the speed should be slow for a realistic effect"move":{"direction":"bottom","enable":true,"outModes":"out","speed":2},// How many particles/snowflakes will be created when starting the effect, density is a good option to enable since it calculates the particles number based on the screen size (mobile users will be happy)"number":{"density":{"enable":true,"area":800},"value":400},// The opacity of the particles/snowflakes"opacity":{"value":0.7},// The shape of the particles/snowflakes, also custom shapes can be used, this will be discussed at the end"shape":{"type":"circle"},// The size of the particles/snowflakes"size":{"value":10},// A nice wobble movement"wobble":{"enable":true,"distance":10,"speed":10},// Some depth to the effect, (the layers count by default is 100, changing max here is not affecting that count)// The zIndex will affect speed, size and opacity of the particles/snowflakes, the smaller the zIndex the smaller/more transparent/slower the particles/snowflakes will be"zIndex":{"value":{"min":0,"max":100}}}}
Vanilla JS
For adding this effect in any website using just plain HTML and JavaScript, you just have to add the snow.json file above in your folder, and add this HTML below in your page.
<script>import{onMount}from"svelte";importsnowConfigfrom"./snow.json";letParticlesComponent;onMount(async ()=>{constmodule=awaitimport("svelte-particles");ParticlesComponent=module.default;});letonParticlesLoaded=(event)=>{constparticlesContainer=event.detail.particles;// you can use particlesContainer to call all the Container class// (from the core library) methods like play, pause, refresh, start, stop};letonParticlesInit=(main)=>{// you can use main to customize the tsParticles instance adding presets or custom shapes};</script><svelte:componentthis="{ParticlesComponent}"id="tsparticles"options="{snowConfig}"/>
Solid JS
For Solid.js web sites/applications this is the recommended setup
For adding this effect in any website using Web Components, you just have to add the snow.json file above in your folder, and add this HTML below in your page.
For adding this effect in any website using jQuery, you just have to add the snow.json file above in your folder, and add this HTML below in your page.
For adding this effect in any website using just plain HTML and JavaScript with just a single script and a line of code, a snow preset is also available. Just add this to your website and you'll have a snow effect immediately.
The object { preset: "snow" } is still a complete tsParticles options object, you can still customize everything, just complete the object with your additional configuration, every options added to that object will override the preset default options.
With this sample, you'll have squared particles/snowflakes instead of the default "circle" value, falling like snow.
You can read more about the snow preset here. A typo was made in the README.md file of the package, the loadFirePreset should be loadSnowPreset.
It's already fixed in the source code, when the new version will be published everything is going to be fine.
Custom Shape
It's possible also to create a custom shape, like a generated snowflake. This is not recommended since a snowflake is heavy to be generated on the go, use images instead. But if someone wants to try it I'll leave the link below.
And it can be used in any of the configuration above, when used in Vanilla JS, jQuery or Web Components with <script> tags you can just add it before calling the tsParticles.load function.
In all the other case refer to the documentation for the particlesInit or init parameter (some component differs in this property) and the parameter of that function is going to replace tsParticles object when calling .addShape method.
For example, React.js component is going to appear like this: