winter.js

Last updated:

Spooky season is over, so the ghosts went home. Time to deck the halls of your website instead. 🎄⛄❄️

A string of lights hangs around the edge of your page and twinkles, chases and fades. Snow falls in front of and behind your content and slowly piles up on top of your boxes and buttons. Every so often a snowman pops up from a corner to wave, and sometimes a snowball comes flying across the screen at him. Click him to throw one yourself.

Live Demo (you're watching it now!)

Watch the snow pile up on these boxes. Wave your mouse through the snow to blow it around, click a bulb to pop it, and when the snowman shows up, click him to throw a snowball his way.

The Porch

Three strands of lights, two of them working.

The Kitchen

Cookies cooling. Do not count them, nobody else did.

The Yard

A snowman went up yesterday. He moves when you're not looking.

The Den

Fire going, cocoa in hand, a movie you've seen 40 times.

Play with it

Change the settings and the page updates. The snippet below the controls updates too, so you can copy the settings you like.

<script src="https://scripts.brebs.net/winter/winter.js"></script>

Quick setup

Add this anywhere on your page. Right before </body> works well.

<script src="https://scripts.brebs.net/winter/winter.js"></script>

Optional settings

To change the defaults, define window.WinterConfig before loading the script. Only include the settings you want to change.

<script>
  window.WinterConfig = {
    snowCount: 120,
    lightsPattern: 'chase',
    snowmanEnabled: true
  };
</script>
<script src="https://scripts.brebs.net/winter/winter.js"></script>
Setting Default Controls
snowCount90Number of snowflakes on screen
snowBackChance0.4Chance a flake falls behind your content (0 to 1)
snowMinSize / snowMaxSize1.2 / 3.6Flake radius range in px
pileUptrueSnow collects on top of boxes, panels and buttons
pileMax12Tallest a pile gets, in px
pileSelectornullCSS selector for what snow piles on, e.g. '.card, nav a'. Leave it null to find boxes automatically
mouseWindtrueMoving the mouse blows the snow around
lightsEnabledtrueWhether the string of lights shows
lightsPattern'cycle''twinkle', 'chase', 'fade', or 'cycle' to switch every 20 seconds
lightsEdgesall fourWhich edges get lights, e.g. ['top'] or ['top', 'bottom']
lightsSidesMinWidth700Below this screen width only the top and bottom lights show, so the sides don't cover text
lightsSpacing46Space between bulbs in px
lightsColorsred, green, gold, blue, pinkBulb colors, e.g. ['#fff', '#9ad'] for icy white
badBulbstrueA bulb flickers or burns out now and then
snowmanEnabledtrueWhether the snowman shows up
snowmanMinDelay / snowmanMaxDelay12000 / 28000Time between snowmen in ms
snowmanSize110Snowman width in px
respectReducedMotiontrueStay off for visitors who prefer reduced motion

Controls

The script adds a Winter object you can call from the console or your own buttons:

Winter.stop();     // clear the snow, lights and snowman
Winter.start();    // bring it all back
Winter.snowman();  // send out a snowman right now
<button onclick="Winter.snowman()">Build a snowman</button>

If the back snow doesn't show up

Snow in the back layer falls underneath your page. If your theme gives both html and body a solid background, the body's background covers it and you'll only see the front snow. Make the body transparent and keep the color on html:

<style>
  body { background: transparent; }
</style>

Get the script

You can use the hosted version directly:

<script src="https://scripts.brebs.net/winter/winter.js"></script>

Self-hosting (if you like doing that)

If you prefer to host the script yourself, you can copy the source and host it anywhere that serves raw JavaScript. When you self-host, you can also change the three quick settings at the top of the file (WINTER_SNOWFLAKES, WINTER_SHOW_LIGHTS and WINTER_SHOW_SNOWMAN) instead of using WinterConfig.

One easy option is use omg.lol amazing service of paste.lol.

  1. Copy or download the code of winter.js
  2. Create a new paste at paste.lol
  3. Name it something like winter.js
  4. Use the /raw version of the paste as your script source
<script src="https://ericmwalk.paste.lol/winter.js/raw"></script>