TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,245
  • Total Topics: 21,354
  • Online today: 565
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 153
  • Total: 153

Snowfall

Started by lurkalot, Today at 10:38:22 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

lurkalot

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>

This website is proudly hosted on Crocweb Cloud Website Hosting.