Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>scroll trigger</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div class="div1">
            <div class="square">
                <h2>this is it square1's description</h2>
            </div>
            <div class="square2">
                <h2>this is it square2's description</h2>
            </div>
            <div class="square3">
                <h2>this is it square3's description</h2>
            </div>
            <div class="square4">
                <h2>this is it square4's description</h2>
            </div>
            <div class="square5">
                <h2>this is it square5's description</h2>
            </div>
            
             
    </div>

    <div class="div2"></div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/gsap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/ScrollTrigger.min.js"></script>
    <script src="app.js"></script>
    

</body>
</html>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto+Mono&display=swap');

* {
    font-family: "FS Pimlico", sans-serif;
    box-sizing: border-box;

}

body {
    margin: 0;
    background: rgb(255, 255, 255);

}

.div1, .div2{
    height: 100vh;
}

.div2{
    background: cyan;
}



.div1{
    background: salmon;
    perspective: 1000px;
    overflow: hidden;
}

.square{                                                         /* right sided   */
    margin-left: 400px;
    height: 200px;
    width: 300px;
    transition: background-color 0.5s ease;
    background: rgb(180, 60, 60);
    position: absolute;
    transform-style: preserve-3d;
    top: 50%;
    right: 30%;
    margin-top: -100px;
    margin-right: -150px;
    z-index: 0;
}

.square h2{
    color:rgb(56, 56, 56);
    margin-top: 220px;
}

.square2{                                                         /* left sided   */
    margin-left: -400px;
    height: 200px;
    width: 300px;
    transition: background-color 0.5s ease;
    background: rgb(255, 255, 255);
    position: absolute;
    transform-style: preserve-3d;
    top: 50%;
    left: 30%;
    margin-top: -100px;
    margin-left: -150px;
    z-index: -1;
}

.square2 h2{
    color:rgb(56, 56, 56);
    margin-top: 220px;
}

.square3{                                                         /* right sided   */
    margin-left: -400px;
    height: 200px;
    width: 300px;
    transition: background-color 0.5s ease;
    background: rgb(255, 255, 255);
    position: absolute;
    transform-style: preserve-3d;
    top: 50%;
    right: 30%;
    margin-top: -100px;
    margin-right: -150px;
    z-index: -2;
}

.square3 h2{
    color:rgb(56, 56, 56);
    margin-top: 220px;
}

.square4{                                                         /* left sided   */
    margin-left: -400px;
    height: 200px;
    width: 300px;
    transition: background-color 0.5s ease;
    background: rgb(255, 255, 255);
    position: absolute;
    transform-style: preserve-3d;
    top: 50%;
    left: 30%;
    margin-top: -100px;
    margin-left: -150px;
    z-index: -3;
}

.square4 h2{
    color:rgb(56, 56, 56);
    margin-top: 220px;
}

.square5{                                                         /* right sided   */
    margin-left: -400px;
    height: 200px;
    width: 300px;
    transition: background-color 0.5s ease;
    background: rgb(255, 255, 255);
    position: absolute;
    transform-style: preserve-3d;
    top: 50%;
    right: 30%;
    margin-top: -100px;
    margin-right: -150px;
    z-index: -4;
}

.square5 h2{
    color:rgb(56, 56, 56);
    margin-top: 220px;
}


              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

gsap.fromTo(".square",{z:0, duration: 1} , {           
    z: 5000,
    duration:8 ,
    ease: "none",
    scrollTrigger: {
        trigger: ".div1",     
        start: "top top",    
        scrub:1,
        toggleActions: "play none none none",       
        markers: true,
        pin: ".div1",
    }
       
})

gsap.fromTo(".square2",{z:-1000, duration: 1} , {              
    z: 4000,
    duration:8 ,
    ease: "none",
    scrollTrigger: {
        trigger: ".div1",     
        start: "top top",    
        scrub:1,
        toggleActions: "play none none none",       
        markers: true,
        pin: ".div1",
    }       
})

gsap.fromTo(".square3",{z:-2000, duration: 1} , {              
    z: 3000,
    duration:8 ,
    ease: "none",
    scrollTrigger: {
        trigger: ".div1",     
        start: "top top",    
        scrub:1,
        toggleActions: "play none none none",       
        markers: true,
        pin: ".div1",
    }       
})

gsap.fromTo(".square4",{z:-3000, duration: 1} , {              
    z: 2000,
    duration:8 ,
    ease: "none",
    scrollTrigger: {
        trigger: ".div1",     
        start: "top top",    
        scrub:1,
        toggleActions: "play none none none",       
        markers: true,
        pin: ".div1",
    }       
})

gsap.fromTo(".square5",{z:-4000, duration: 1} , {              
    z: 1000,
    duration:8 ,
    ease: "none",
    scrollTrigger: {
        trigger: ".div1",     
        start: "top top",    
        scrub:1,
        toggleActions: "play none none none",      
        markers: true,
        pin: ".div1",
    }       
})

              
            
!
999px

Console