how to create snow effect Christmas

how to create snow effect Christmas

how to create snow effect Christmas

Before We Start

Every developers need, clean and modern elements to develop their websites, It contain pictures and a user interface element within a website. The most important one and the first section that the user sees when he/she enters a website. how to create snow effect Christmas

So if you are a person who wishes to develop a website, you have to know how to create that properly.

how to create snow effect Christmas

We are here to solve your problem. In this article we discuss how to create this elements. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag.

/* so the snow is visible only */
body {
  background:linear-gradient(to top, navy, black);

Step 3 – Add JavaScript

And also copy and paste below JavaScript code between <script></script> tag.

var snow_fall_rate = 5 //decrease for faster fall speed
function snow() {  
  var b = document.createElement('div')
  var size = (Math.random()*10) + 5
  b.className = 'flake'
  b.style.width = size + 'px'
  b.style.height = size + 'px'
  b.style.position = 'fixed'
  b.style.zIndex = '9999'
  b.style.left = Math.random()*window.innerWidth + 'px'
  b.style.top = '-20px'
  b.style.borderRadius = '50%'
  b.style.background = 'white'  
  b.style.opacity = '.5'  
  b.style.filter = Math.random() < .5 ? 'blur(3px)' : 'blur(1px)'
  b.style.transition = Math.random < .5 ? snow_fall_rate*.75 + 's' : snow_fall_rate + 's'
  b.style.transitionTimingFunction = 'ease-in'

    var flakes = document.querySelectorAll('.flake')
    var flake = flakes[flakes.length - 1]  
    var flake_loc = flake.getBoundingClientRect()
    flake.style.top = '105%'
    flake.style.left = Math.random() < .5 ? flake_loc.left - 150 + 'px' : flake_loc.left + 150 + 'px'

  var flakes = document.getElementsByClassName('flake')
  for(var i=0;i<flakes.length;i++){
    if(flakes[i].getBoundingClientRect().top > window.innerHeight) {
  setTimeout(function(){ snow() },200)

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want.Enjoy it.

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.

Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

One Comment

Leave a Reply

Your email address will not be published.

Back to top button