Loading Now

How to Add Snowfall Animation in Shopify Store (Free)

Add Snowfall Animation in Shopify

The holiday season is a fantastic time to give your Shopify store a festive touch, and one of the easiest ways to do this is by adding snowfall animation. Adding snowfall animation in Shopify creates an enchanting experience for your visitors, making your store feel more welcoming during the colder months.

pngwing.com-1 How to Add Snowfall Animation in Shopify Store (Free)

In this blog, we’ll walk you through how to add snowfall animation in Shopify, using a simple code snippet that you can apply to your store. Best of all, it’s completely free to implement!

Why Add Snowfall Animation in Shopify?

Snowfall animation in Shopify provides a visually appealing, wintery ambiance that aligns perfectly with the holiday season. It can boost engagement by making the shopping experience more immersive and enjoyable. Not only does it enhance the look of your store, but it can also create a memorable atmosphere that encourages customers to stay longer and make purchases.

Step-by-Step Guide to Add Snowfall Animation in Shopify

To add snowfall animation in Shopify, follow these easy steps. You don’t need to be a coding expert to implement this! Here’s the code you’ll need:

Read Also: How to add animation in and edit text of Buy Button in Shopify

1. Add the HTML Code

First, add a div element to your Shopify theme’s code. This div will act as the container for the snowfall effect.

<div id="snowfall-container"></div>

Place this inside your theme’s main HTML file, typically located in the theme.liquid file.

2. Add CSS for Snowfall Effect

Next, you need to apply the CSS styles to create the snowfall effect. This will style the div and create the animation.

<style>
  body {
    background: black;
    margin: 0;
    font-family: Arial, sans-serif;
  }

  #snowfall-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 9999;
  }

  .snow-flake {
    position: absolute;
    filter: blur(1px);
    top: -50px;
    animation: snow-fall linear infinite;
  }

  @keyframes snow-fall {
    0% {
      transform: translateY(0px);
    }
    25% {
      transform: translateX(50px) translateY(25vh);
    }
    50% {
      transform: translateY(50vh);
    }
    75% {
      transform: translateX(-50px) translateY(75vh);
    }
    100% {
      transform: translateY(calc(100vh + 50px));
    }
  }
</style>

This CSS code defines the appearance of the snowflakes and the animation that makes them fall. The #snowfall-container will be the overlay for the snow, ensuring it covers the entire screen.

3. Add the JavaScript for Dynamic Snowflakes

Now, we need JavaScript to generate multiple snowflakes with varying sizes, speeds, and colors. This script will create a realistic snowfall effect that looks great on your Shopify store.

<script>
  const rnd = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);

  const settings = {
    density: {{ section.settings.snowflake_density | times: 10 }},
    speedMin: {{ section.settings.snowflake_speed_min }},
    speedMax: {{ section.settings.snowflake_speed_max }},
    color: "{{ section.settings.snowflake_color }}",
    sizeMin: {{ section.settings.snowflake_size_min }},
    sizeMax: {{ section.settings.snowflake_size_max }}
  };

  for (let ndx = 0; ndx < settings.density; ndx++) {
    const flake = document.createElement("span");
    flake.innerText = "*";
    flake.setAttribute("class", "snow-flake");
    const style = `
      color: ${settings.color}; 
      left: ${rnd(-10, window.innerWidth + 10)}px; 
      animation-duration: ${rnd(settings.speedMin, settings.speedMax)}s; 
      animation-delay: ${rnd(0, 15)}s; 
      font-size: ${rnd(settings.sizeMin, settings.sizeMax)}px`;
    flake.setAttribute("style", style);
    document.getElementById("snowfall-container").appendChild(flake);
  }
</script>

This JavaScript code uses random values for each snowflake’s position, size, speed, and color. It creates a more natural effect, as each snowflake behaves differently.

4. Add Customizable Options (Optional)

If you want to give your users more control over the snowfall effect, you can add customizable options in your Shopify theme settings. Here is the code you’ll use to enable settings such as snowflake density, speed, and color:

{% schema %}
{
  "name": "Snowfall Effect",
  "settings": [
    {
      "type": "range",
      "id": "snowflake_density",
      "label": "Snowflake Density",
      "default": 20,
      "min": 10,
      "max": 100,
      "step": 10
    },
    {
      "type": "range",
      "id": "snowflake_speed_min",
      "label": "Snowflake Minimum Speed (seconds)",
      "default": 10,
      "min": 5,
      "max": 25,
      "step": 1
    },
    {
      "type": "range",
      "id": "snowflake_speed_max",
      "label": "Snowflake Maximum Speed (seconds)",
      "default": 20,
      "min": 10,
      "max": 30,
      "step": 1
    },
    {
      "type": "range",
      "id": "snowflake_size_min",
      "label": "Snowflake Minimum Size (px)",
      "default": 10,
      "min": 5,
      "max": 20,
      "step": 1
    },
    {
      "type": "range",
      "id": "snowflake_size_max",
      "label": "Snowflake Maximum Size (px)",
      "default": 25,
      "min": 15,
      "max": 40,
      "step": 1
    },
    {
      "type": "color",
      "id": "snowflake_color",
      "label": "Snowflake Color",
      "default": "#ffffff"
    }
  ]
}
{% endschema %}

This JSON schema will allow you to adjust the density, speed, size, and color of the snowflakes directly from the Shopify theme settings.

Conclusion

Adding snowfall animation in Shopify is a fantastic way to bring some winter magic to your store. By following these simple steps, you can easily add a beautiful snowfall effect to your website without spending any money. It will definitely create a memorable shopping experience for your customers and make your store stand out during the holiday season.

To add snowfall animation in Shopify for free, just follow the steps outlined above, and you’ll have a stunning, festive site in no time.

Share this content:

Post Comment