How would I go about creating fake snow using vanilla JavaScript?

Hi

I’m relatively new to JS and am attempting to create a simple vanilla JS library that adds a snowfall feature on a website. I’m kind of unsure how i would even go about starting it so was wondering if anyone could help offer some tips to get me started.

Right now where my brain is at: I feel the math.random function is gonna be very helpful and rather than using an image or css to create the snowflakes I was thinking just use an icon like '❄'. Then i guess i’ll need a max snowflakes on screen at a time + once falls out of users screen remove the element.

What i’m unsure about is how do i create the snowfall. A for loop? Do i spam the dom and inject 50 snowflakes etc.?

What would you suggest is a clean way to approach this and also in a way that wouldn’t cause lag? Thanks so much.

https://erikwatson.github.io/snowfall-editor/

All that would be left to do is change the white circles to the icon using css.

It would be more beneficial to learn to install and use npm packages and use them in your project than it would be to create a snowfall effect from scratch.

Learning to use supported npm packages will reduce bugs/risks, and increase productivity significantly.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.