MediaWiki:Common.js: Difference between revisions

From Tony Chase
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () {
    var container = document.body;
            const container = document.body;
    var numberOfSnowflakes = 50;
            const numberOfSnowflakes = 50;
    var maxAccumulatedHeight = 200;
            const maxAccumulatedHeight = 200;
    var accumulatedHeight = 0;
            let accumulatedHeight = 0;


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


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


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


        snowflake.style.left = startX + "px";
                snowflake.style.left = `${startX}px`;
        snowflake.style.top = startY + "px";
                snowflake.style.top = `${startY}px`;


        var size = Math.random() * 5 + 3;
                const size = Math.random() * 5 + 3;
        snowflake.style.width = size + "px";
                snowflake.style.width = `${size}px`;
        snowflake.style.height = size + "px";
                snowflake.style.height = `${size}px`;
 
                animateSnowflake(snowflake);
            }


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


    function animateSnowflake(snowflake) {
                function moveSnowflake() {
        var speed = 1 + Math.random() * 2;
                    const currentTop = parseFloat(snowflake.style.top);
                    const newTop = currentTop + speed;


        function moveSnowflake() {
                    snowflake.style.top = `${newTop}px`;
            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 (newTop > window.innerHeight) {
                        if (accumulatedHeight >= maxAccumulatedHeight) {
                accumulatedHeight += window.innerHeight;
                            accumulatedHeight = 0;
                snowflake.style.top = -accumulatedHeight + "px";
                        }
                snowflake.style.left = Math.random() * window.innerWidth + "px";
                    }


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

Revision as of 23:07, 4 December 2023

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

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

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

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

                snowflake.style.left = `${startX}px`;
                snowflake.style.top = `${startY}px`;

                const size = Math.random() * 5 + 3;
                snowflake.style.width = `${size}px`;
                snowflake.style.height = `${size}px`;

                animateSnowflake(snowflake);
            }

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

                function moveSnowflake() {
                    const currentTop = parseFloat(snowflake.style.top);
                    const 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();
            }
        });