Name of Snippet: Snowfall
SMF/TP versions tested:: SMF2.1.8/TP 3.0.5
Block Type:: html & javascript
Description: Adds Falling Snow. (as seen on our home page in December)
- Put code in a html & javascript block,
- Allow block to collapse: Do not allow block to collapse
- set the frame options: Do not use title/frame styles
- Choose where the block should appear.
- Save.
<style>
.snowflake {
position: fixed;
top: -40px;
pointer-events: none;
user-select: none;
z-index: 9999;
color: #fff;
text-shadow:
0 0 4px #fff,
0 0 8px rgba(255,255,255,.8);
}
@keyframes snowfall {
0% {
transform:
translateX(0px)
translateY(0px)
rotate(0deg);
}
25% {
transform:
translateX(var(--drift))
translateY(25vh)
rotate(90deg);
}
50% {
transform:
translateX(calc(var(--drift) * -1))
translateY(50vh)
rotate(180deg);
}
75% {
transform:
translateX(var(--drift))
translateY(75vh)
rotate(270deg);
}
100% {
transform:
translateX(calc(var(--drift) * -1))
translateY(110vh)
rotate(360deg);
}
}
</style>
<script>
(function () {
const flakes = ['❄','❅','❆'];
function createSnowflake() {
const flake = document.createElement('div');
flake.className = 'snowflake';
flake.innerHTML =
flakes[Math.floor(Math.random() * flakes.length)];
const size = Math.random() * 22 + 8;
const duration = Math.random() * 10 + 10;
const opacity = Math.random() * 0.2 + 0.8;
const drift =
(Math.random() * 120 + 40) *
(Math.random() > 0.5 ? 1 : -1);
flake.style.left =
Math.random() * window.innerWidth + 'px';
flake.style.fontSize = size + 'px';
flake.style.opacity = opacity;
flake.style.setProperty('--drift', drift + 'px');
flake.style.animation =
`snowfall ${duration}s linear forwards`;
document.body.appendChild(flake);
setTimeout(() => {
flake.remove();
}, duration * 1000);
}
setInterval(createSnowflake, 300);
})();
</script>