BACK TO Articles

Bring seasonal sparkle to your website with this simple script

By Tim McVinish

‘Tis the season for festive websites

Well, it’s the holiday season. While our homes, shopping centres, and everything else around us gets a sprinkle of holiday magic, websites are often overlooked. So today we’re going to explore creating a simple script that can be used to add a little festive flare to any website. This script will display a wreath and countdown to Christmas that, when clicked, triggers a whimsical snowflake animation. Let’s dive into the details!

Getting your digital decorating kit ready

Before we start decking the digital halls, let’s run through everything needed to add some festive flair to your website. You’ll need:

Essential tools

  • Access to your website’s code or the ability to add a script (more on that later)
  • A code editor
  • Basic understanding of HTML, CSS, and JavaScript
  • Holiday-themed images (PNG files with transparent backgrounds are preferred). We’re using a wreath.
  • Somewhere to host the image so our script can reference it

Step 1: Pulling out the digital decos

Just like with decorating the house, lets first open our cupboard and dig out our decorations. Personally I’m a minimalist, so we’ll keep things simple for this demo. Feel free to go as over-the-top-tacky-tinsel-too-many-fairy-lights-festive as you desire though.

const wrapper = document.createElement('div');
wrapper.id = 'the-wrapping';
    
const image = document.createElement('img');
image.id = 'digital-decoration';
image.src = '../../../assets/img/xmas-decoration-trimmed.png';

const countdown = document.createElement('div');
countdown.id = 'christmas-countdown';
countdown.textContent = 25 - new Date().getDate();
    
wrapper.appendChild(image);  
wrapper.appendChild(countdown);
document.body.appendChild(wrapper);

Here we’ve got a wrapper to contain everything, a png of a Christmas wreath, and a simple countdown display the sleeps till Christmas.

Step 2: Hanging the garlands

We’ll use a dash of super special Christams CSS to place our decorations on the page. This will include styles, positioning and animations. Again, feel free to add your own spin and create your own winter wonderland.

First, we need to define the styles for our Christmas-themed elements. This includes positioning, animations, and responsive design. Here’s how you can do it:


const styles = document.createElement('style');
  
styles.textContent = `
  #the-wrapping {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: 50px; // position as you desire
    right: 50px; // position as you desire
    width: 120px; // size as you desire
    height: 120px; // size as you desire
    text-align: center;
    font-size: 1rem;
    background-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    z-index: 1001;
    cursor: pointer;
    user-select: none;
  }

  #digital-decoration {
    position: absolute;
    top: 2px;
    left: 6px;
    width: 114px;
    z-index: 1001;
    animation: sway 2s ease-in-out infinite;
  }

  #christmas-countdown {
    width: 118px;
    font-size: 2rem;
    font-weight: bold;
    color: #333;
  }

  @keyframes sway {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
  }

  .snowflake {
    position: fixed;
    pointer-events: none;
    animation: fall linear forwards;
    z-index: 1000;
  }

  @keyframes fall {
    to {
      transform: translateY(100vh);
      opacity: 0;
    }
  }
`;
document.head.appendChild(styles);

Step 3: A sprinkle of javascript magic

Those with a keen eye may have noticed the snowflake class in our css. “But there were no snowflakes in step 1!?”. This is for a final touch, a fun little click animation that creates a snow shower upon clicking our festive finishings. With that said, let’s add a listener for click events on our decorations and then trigger a createSnowflake function.

const christmasDecoration = document.getElementById('the-wrapping');
christmasDecoration.addEventListener('click', () => {
  // Create snowflake effect
  for (let i = 0; i < 10; i++) {
    createSnowflake();
  }
});

function createSnowflake() {
  const snowflake = document.createElement('div');
  snowflake.innerHTML = '❄';
  snowflake.className = 'snowflake';
  snowflake.style.left = `${christmasDecoration.offsetLeft + Math.random() * 110}px`;
  snowflake.style.top = `${christmasDecoration.offsetTop}px`;
  snowflake.style.fontSize = `${Math.random() * 10 + 10}px`;
  snowflake.style.animationDuration = `${Math.random() * 8 + 1}s`;
    
  document.body.appendChild(snowflake);
    
  // Remove snowflake after animation
  setTimeout(() => {
    snowflake.remove();
  }, 3000);
}

Now, when our decorations are clicked a flurry of frosty flakes will float over our site. Magical!

Step 4: Spread the Christmas cheer

Now, how do we deploy this? Well that will depend on where your site lives. If you have access to your code base then you can simply wrap the script in some <script> tags and paste it where you please. If you’re using a platform like WordPress, Wix, or Squarespace, then you should be able to inject a script into your site via your dashboard. Below are some guides for these platforms. If you’re using a different platform Google should be able to help you out. Most platforms will provide a way to inject scripts.

And that’s a wrap! Please feel free to share any magical creations or alterations you come up with.

Guides for adding scripts to popular website platforms:

The complete script

(function () {
	// content
	const wrapper = document.createElement('div');
	wrapper.id = 'the-wrapping';
    
	const image = document.createElement('img');
	image.id = 'digital-decoration';
	image.src = './path-to-your-image/your-image.png'; // replace with the path                            
        to your image

	const countdown = document.createElement('div');
        countdown.id = 'christmas-countdown';
        countdown.textContent = 25 - new Date().getDate();
    
        wrapper.appendChild(image);  
        wrapper.appendChild(countdown);
        document.body.appendChild(wrapper);
  
        // styles
        const styles = document.createElement('style');
  
        styles.textContent = `
	    #the-wrapping {
	      position: fixed;
	      display: flex;
	      align-items: center;
	      justify-content: center;
	      bottom: 50px;
	      right: 50px;
	      width: 120px;
	      height: 120px;
	      text-align: center;
	      font-size: 1rem;
	      background-color: rgba(255, 255, 255, 0.9);
	      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
	      border-radius: 50%;
	      z-index: 1001;
	      cursor: pointer;
	      user-select: none;
	    }

	    #digital-decoration {
	      position: absolute;
	      top: 2px;
	      left: 6px;
	      width: 114px;
	      z-index: 1001;
	      animation: sway 2s ease-in-out infinite;
	    }

	    #christmas-countdown {
	      width: 118px;
	      font-size: 2rem;
	      font-weight: bold;
	      color: #333;
	    }

	    @keyframes sway {
	      0%, 100% { transform: rotate(-5deg); }
	      50% { transform: rotate(5deg); }
	    }

	    .snowflake {
	      position: fixed;
	      pointer-events: none;
	      animation: fall linear forwards;
	      z-index: 1000;
	    }

	    @keyframes fall {
	      to {
	        transform: translateY(100vh);
	        opacity: 0;
	      }
	    }
	  `;
	   document.head.appendChild(styles);

	  // functionality
	  const christmasDecoration = document.getElementById('the-wrapping');
	  christmasDecoration.addEventListener('click', () => {
	    // Create snowflake effect
	    for (let i = 0; i < 10; i++) {
	      createSnowflake();
	    }
	  });

	  function createSnowflake() {
	    const snowflake = document.createElement('div');
	    snowflake.innerHTML = '❄';
	    snowflake.className = 'snowflake';
	    snowflake.style.left = `${christmasDecoration.offsetLeft + Math.random()   
            * 110}px`;
	    snowflake.style.top = `${christmasDecoration.offsetTop}px`;
	    snowflake.style.fontSize = `${Math.random() * 10 + 10}px`;
	    snowflake.style.animationDuration = `${Math.random() * 8 + 1}s`;
    
	    document.body.appendChild(snowflake);
    
	    // Remove snowflake after animation
	    setTimeout(() => {
	      snowflake.remove();
	    }, 3000);
	  }
	})();

Looking for something specific?

Search our Archive to find content that piques your interest.
SEARCH

Recents Posts

February 20, 2025
AI, innovation & project management: what we discovered at our Hackathon 
By Pooja Keshanagari AI is transforming industries, helping businesses work smarter, not harder. But if you’re new to AI, you might be wondering: Where do I even start?  One of the things I love about Mojo Soup is that we believe innovation isn’t about waiting for the future - it’s about building it. One of…
Read more
February 18, 2025
Before you add AI to Power Platform and Dynamics 365, fix this first
By Daniel Monger Artificial intelligence is transforming the way businesses use Power Platform and Dynamics 365, but before you dive in, it’s important to understand the differences between these two platforms and how AI fits into them. Understanding AI in Dynamics 365 vs Power Platform Dynamics 365Microsoft has embedded AI-driven Copilot features across its suite…
Read more
February 13, 2025
AI for beginners: How I used AI to level up my half-marathon training
By Iris Monod Disclaimer: This blog is based on personal experience and is not professional health, fitness, or nutritional advice. Always consult a qualified professional before starting any new exercise or diet plan. When I started my journey as a newbie runner wanting to conquer longer runs and set my goals towards a half-marathon, I…
Read more
February 4, 2025
Dynamics 365 vs Power Platform: which is best for your business?  
By Maxine Harwood When it comes to selecting the right tools for your business operations, the choice between Dynamics 365 and the Power Platform can feel a bit like walking into Bunnings. Imagine standing in the tool shop aisle: do you invest in a few specific tools to craft something custom for your requirements, or…
Read more