MediaWiki:Common.js: Difference between revisions

From Tony Chase
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 36: Line 36:
             snowflake.style.top = newTop + "px";
             snowflake.style.top = newTop + "px";


             if (newTop > document.body.scrollHeight) {
             if (newTop > window.innerHeight) {
                 accumulatedHeight += document.body.scrollHeight;
                 accumulatedHeight += window.innerHeight;
                 snowflake.style.top = -accumulatedHeight + "px";
                 snowflake.style.top = -accumulatedHeight + "px";
                 snowflake.style.left = Math.random() * window.innerWidth + "px";
                 snowflake.style.left = Math.random() * window.innerWidth + "px";

Revision as of 23:05, 4 December 2023

document.addEventListener("DOMContentLoaded", function () {
    var container = document.body;
    var numberOfSnowflakes = 50;
    var maxAccumulatedHeight = 200;
    var accumulatedHeight = 0;

    for (var i = 0; i < numberOfSnowflakes; i++) {
        createSnowflake();
    }

    function createSnowflake() {
        var snowflake = document.createElement("div");
        snowflake.className = "snowflake";
        container.appendChild(snowflake);

        var startX = Math.random() * window.innerWidth;
        var startY = Math.random() * window.innerHeight;

        snowflake.style.left = startX + "px";
        snowflake.style.top = startY + "px";

        var size = Math.random() * 5 + 3;
        snowflake.style.width = size + "px";
        snowflake.style.height = size + "px";

        animateSnowflake(snowflake);
    }

    function animateSnowflake(snowflake) {
        var speed = 1 + Math.random() * 2;

        function moveSnowflake() {
            var currentTop = parseFloat(snowflake.style.top);
            var newTop = currentTop + speed;

            snowflake.style.top = newTop + "px";

            if (newTop > window.innerHeight) {
                accumulatedHeight += window.innerHeight;
                snowflake.style.top = -accumulatedHeight + "px";
                snowflake.style.left = Math.random() * window.innerWidth + "px";

                if (accumulatedHeight >= maxAccumulatedHeight) {
                    accumulatedHeight = 0;
                }
            }

            requestAnimationFrame(moveSnowflake);
        }

        moveSnowflake();
    }
});