Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <title>Vicsta</title>
    <meta charset="UTF-8">
</head>
<body>
<div class="container"></div>
<div class="tree"></div>
<div class="sky"></div>
</body>
              
            
!

CSS

              
                body {
    background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOqAYx_EWybWkdj5XFGuSUbOW6Wx8tPBxb7Rd5uADV89kMCDNaZr2jvYCIoSJ-QzRTAboIkolpBH0mQQFZUUxMIBXWBdLlmTelx0tFbk9FWX1knkqiy-1F_eo1XI-ZTzYcXN3hpdTr8oL2jh9X8IaLw8VfZzpGdx0t916zdKbX4KKJ7IbvqdEYZ_rg/s1600/Daun%20Berjatuhan.jpg) no-repeat fixed;
    background-size: 100% 100%;
}

::-webkit-scrollbar
{
    width: 0.5vw;  /* for vertical scrollbars */
    height: 0.5vw; /* for horizontal scrollbars */
}

::-webkit-scrollbar-track
{
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb
{
    background: rgba(0, 0, 0, 0.5);
}

.container {
    width: 100%;
    height: 100%;
}

.leaf0, .leaf1{
    position: fixed;
    background: url("https://image.ibb.co/h57i1d/Black_Leaf0.png") no-repeat;
    background-size: contain;
    z-index: -500;
    display: none;
    -webkit-transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
}

.leaf1 {
    position: fixed;
    background: url("https://image.ibb.co/fA8Z7J/Black_Leaf1.png") no-repeat;
    background-size: contain;
    z-index: -500;
    display: none;
    -webkit-transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
}

.snowflake0 {
    background: url("https://image.ibb.co/iG6yZy/Snowflake0.png") no-repeat;
    position: fixed;
    width: 10px;
    height: 10px;
    background-size: contain;
    z-index: -500;
    -webkit-transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
}

.tree {
    visibility: hidden;
    position: fixed;
    top: 15vh;
    left: 2vw;
    height: 25vh;
    width: 22vw;
    background: red;
}

.sky {
    visibility: hidden;
    position: fixed;
    top: 0;
    left: 0;
    height: 10vh;
    width: 100vw;
    background: skyblue;
}
              
            
!

JS

              
                window.addEventListener('load',
    function () {
                let numLeaves = 60;
                let numSnow = 50;
                let curLeaves = 0;
                let curSnow = 0;

                let didScroll = false;

                function scrolled() {
                    didScroll = true;
                    window.removeEventListener("scroll", scrolled);
                }

                window.addEventListener("scroll", scrolled);

                let wait = 800;

                setInterval(function() {
                    if(didScroll) {
                        didScroll = false;
                        let cur = (document.documentElement.scrollTop || document.body.scrollTop);
                        let loc = cur / ((document.documentElement.scrollHeight || document.body.scrollHeight) - window.innerHeight) * 100;
                        if (loc < 25) {
                            numLeaves = 60;
                            numSnow = 0;
                            wait = 800;
                        } else if (loc < 50) {
                            numLeaves = 100;
                            numSnow = 20;
                            wait = 500;
                        } else if (loc < 75) {
                            numLeaves = 20;
                            numSnow = 110;
                            wait = 300;
                        } else {
                            numLeaves = 35;
                            numSnow = 25;
                            wait = 1000;
                        }
                        window.addEventListener("scroll", scrolled);
                    }
                }, 750);

                /*
                                PROCEDURE TO CONTROL BACKGROUND ANIMATIONS
                                 */

                let height = document.documentElement.clientHeight;

                let width = Math.max(
                    document.documentElement.clientWidth,
                    document.body.scrollWidth,
                    document.documentElement.scrollWidth,
                    document.body.offsetWidth,
                    document.documentElement.offsetWidth
                );

                window.addEventListener("resize", function () {
                    height = document.documentElement.clientHeight;


                    width = Math.max(
                        document.documentElement.clientWidth,
                        document.body.scrollWidth,
                        document.documentElement.scrollWidth,
                        document.body.offsetWidth,
                        document.documentElement.offsetWidth
                    );
                });

                let dir = [];
                let speed = [];
                let grav = [];
                let wind = [];
                let rot = [];
                let delta = [];

                function createChild(parent, childName) {
                    let bound = parent.getBoundingClientRect();
                    let startX = ((Math.random() * (bound.right - bound.left)) + bound.left) + "px";
                    let startY = ((Math.random() * (bound.bottom - bound.top)) + bound.top) + "px";

                    let newChild = document.createElement("div");

                    newChild.style.top = startY;
                    newChild.style.left = startX;
                    newChild.style.transform = randomRotate();
                    let z = newChild.style.transform.split(" ")[2].replace("rotateZ(", "").replace("deg)", "");
                    grav.push(Math.random() / 6 + 0.3);
                    speed.push(Math.random() / 6 + 1);
                    if (childName === "leaf") {
                        wind.push(Math.random() / 4 + 0.5);
                        newChild.className = childName + Math.floor(Math.random() * 2);
                        let random = Math.random() * 15;
                        newChild.style.width = (60 - random) + "px";
                        newChild.style.height = (60 - random) + "px";
                    } else {
                        wind.push(0.2);
                        newChild.className = childName + Math.floor(Math.random());
                        let random = Math.random() * 5;
                        newChild.style.width = (10 - random) + "px";
                        newChild.style.height = (10 - random) + "px";
                    }
                    rot.push(Math.random() / 4 + 0.4);
                    delta.push(Math.random() * 40 - 20);
                    if (z < 90) {
                        dir.push(-1);
                    } else {
                        dir.push(1);
                    }

                    document.getElementsByClassName("container")[0].appendChild(newChild);
                    $(newChild).fadeIn("slow");
                }

                function randomRotate() {
                    let x = Math.random() * 10;
                    let y = Math.random() * 30 - 15;
                    let z = Math.random() * 180;
                    return "rotateX(" + x + "deg) rotateY(" + y + "deg) rotateZ(" + z + "deg)";
                }

                //Animates the children of a given parent to fall
                function animate(parent) {

                    if (curLeaves < numLeaves) {
                        let bound = (numLeaves - curLeaves);
                        for (let i = 0; i < bound; i++) {
                            setTimeout(function () {
                                createChild(document.getElementsByClassName("tree")[0], "leaf");
                            }, (wait * i));
                            curLeaves++;
                        }
                    }

                    if (curSnow < numSnow) {
                        let bound = (numSnow - curSnow);
                        for (let i = 0; i < bound; i++) {
                            setTimeout(function () {
                                createChild(document.getElementsByClassName("sky")[0], "snowflake");
                            }, ((wait + 100) * i));
                            curSnow++;
                        }
                    }

                    for (let i = 0; i < parent.children.length; i++) {
                        let child = parent.children[i];
                        let z = child.style.transform.split(" ")[2].replace("rotateZ(", "").replace("deg)", "");
                        let dx = speed[i];
                        let dy = Math.random() * 2 * Math.abs(Math.cos(z * Math.PI / 180));
                        if (child.className.indexOf("leaf") >= 0) {
                            child.style.top = (child.style.top.replace("px", "") - (0.2 * Math.sin(z / 180 * Math.PI)) + grav[i] + "px");
                        } else {
                            child.style.top = (child.style.top.replace("px", "") - 0 + grav[i] + "px");
                        }
                        child.style.left = (child.style.left.replace("px", "") - 0 - (0.1 * Math.sin(z / 180 * Math.PI)) + (dir[i] * speed[i] * 1.5) + wind[i]) + "px";

                        if ((child.style.top.replace("px", "") - 0 + dy) > height || (child.style.left.replace("px", "") - 0 + dx) > width || (child.style.left.replace("px", "") - 0 + dx) < -100) {
                            parent.removeChild(child);
                            dir.splice(i, 1);
                            speed.splice(i, 1);
                            wind.splice(i, 1);
                            grav.splice(i, 1);
                            rot.splice(i, 1);
                            delta.splice(i, 1);
                            if (child.className.indexOf("leaf") >= 0) {
                                curLeaves--;
                            } else {
                                curSnow--;
                            }
                            i--;
                        } else {
                            if (z >= 92 && dir[i] === -1) {
                                if (speed[i] > 0) {
                                    speed[i] -= speed[i] / 50;
                                }
                            } else if (z >= 100 && dir[i] === 1) {
                                if (speed[i] < 1.1) {
                                    speed[i] += 0.02;
                                }
                            } else if (z <= 80 && dir[i] === -1) {
                                if (speed[i] < 1.1) {
                                    speed[i] += 0.03;
                                }
                            } else if (z <= 88 && dir[i] === 1) {
                                if (speed[i] > 0) {
                                    speed[i] -= speed[i] / 50;
                                }
                            }

                            if (z <= 92 && z >= 88) {
                                speed[i] = 1 + (Math.random() / 4);
                            }

                            if ((z <= 140 && dir[i] === -1 && speed[i] > 0.22) || (z >= 20 && dir[i] === 1 && speed[i] > 0.22)) {
                                z = z - (dir[i] * rot[i]);
                            }

                            if (z >= 110 && speed[i] <= 0.2 && dir[i] === -1) {
                                dir[i] = 1;
                            } else if (z < 70 && speed[i] <= 0.2 && dir[i] === 1) {
                                dir[i] = -1;
                            }

                            let x = child.style.transform.split(" ")[0].replace("rotateX(", "").replace("deg)", "");
                            if (x > 0 + delta[i] && dir[i] === -1) {
                                x = x - Math.random() / 2;
                            } else if (x < 40 + delta[i] && dir[i] === 1) {
                                x = x - 0 + Math.random() / 2;
                            }

                            let y = child.style.transform.split(" ")[1].replace("rotateY(", "").replace("deg)", "");
                            if (y > 0 + delta[i] && dir[i] === -1) {
                                y = y - Math.random() / 2;
                            } else if (y < 40 + delta[i] && dir[i] === 1) {
                                y = y - 0 + Math.random() / 2;
                            }

                            child.style.transform = "rotateX(" + x + "deg) rotateY(" + y + "deg) rotateZ(" + z + "deg)";
                        }
                    }
                }

                setInterval(function () {
                    animate(document.getElementsByClassName("container")[0]);
                }, 10);

                /*
                END OF PROCEDURE
                 */
                

    }, false);
              
            
!
999px

Console