IMPORTANT
Help UKRAINE ! Your action matters!
Donate to support Ukrainian Army!
Donate to charity funds!
Organize/join street protests in your city to support Ukraine and condemn Russian aggression!
Expose and report Russian disinformation! #StandWithUkraine
Christmas is almost here and the festive atmosphere kicks in. Let’s learn how we can add some of that winter/holiday spirit to our Power Pages site. In this article, you will find a couple of ways to add a snowfall animation to your site.
Snowfall with CSS only
In the first approach, we will be using CSSnowflakes, which is a combination of CSS and HTML without any JS.
This is what our final result will look like:
Let’s start by creating a new Web Template called “Snowfall with CSS Only”. We will place the following code there:
snowflake class allows us to change the properties of the snowflakes on our page (like size, colour, etc).
To add more snowflakes you would need to create new divs inside the snowflakes container and update the corresponding CSS (currently each snowflake has its own animation delay and position, so when adding a new one we need to create additional CSS for it).
The aria-hidden attribute is added to the snowflakes container to hide it from screen readers.
Then we will add a Site Setting called Snowfall/Enabled and set it to true. This setting will allow us to turn snow on and off without changes in our code.
Then we will add the following code to the Header web template, so it will apply to all pages with the header
Snowfall with JS
For the second approach, we will generate our snowfall using JS (from this CodePen).
Our final result will look like this:
We will create a new Web Template called “Snowfall with JS”. We will place the following code there:
This version of the code allows you to customize fall speed, number of snowflakes, if snowfall pauses if there is no interaction with the page for some time etc. See the code for the full list of available options.
The aria-hidden attribute is added to the snowflakes container to hide it from screen readers.
Similarly to the CSS-only approach we need to have a site setting to control our snowfall visibility without change to the code. Add a Site Setting called Snowfall/Enabled and set it to true if you didn’t do so in the previous example.
Then we will add the following code to the Header web template, so it will apply to all pages with the header
Conclusion
In this article, I showed you a couple of ways to add a winter spirit to your website by enabling snowfall animation. These code snippets can be further enhanced by adding, for example, a custom button that allows users to enable/disable animation dynamically.
If you liked this article, please subscribe so you don't miss any future post.