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

              
                <div class="scrollContainer">

  <div class="bg-wrapper">
    <div id="bg" class="sections">homepage</div>
    <div id="bg1" class="sections">#1</div>
    <div id="bg2" class="sections">#2</div>
    <div id="bg3" class="sections">#3</div>
    <div id="bg4" class="sections">#4</div>
    <div id="bg5" class="sections">#5</div>
    <div id="bg6" class="sections">#6</div>
  </div>
  
  
</div>
              
            
!

CSS

              
                body{
  height:1400vh;
  margin: 0;
  padding: 0;
  background-color: black;
}

.scrollContainer{
  width: 100vw;
  height:100vh;
  position: fixed;
}

.bg-wrapper{
  margin: 0;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  z-index: 1;
  position: fixed;
  width: 100vw;
  height:100vh;
}
.sections{
  font-size:2em;
  position:absolute;
  width: 100%;
  height:100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
#bg{
  background: linear-gradient(pink, gray, dimgray, gray, red, black);
}
  
#bg1 {
  background: linear-gradient(black,pink, gray, dimgray, gray, red, black);
}

#bg2 {
  background: linear-gradient(black, pink, pink, black);
}

#bg3 {
  background: linear-gradient(black, blue, black);
}

#bg4 {
  background: linear-gradient(black, pink, pink, black);
}

#bg5 {
  background: linear-gradient(black, yellow, black);
}

#bg6 {
  background: linear-gradient(black, yellow, black);
}
              
            
!

JS

              
                // init funtion
function init(){
  gsap.registerPlugin(ScrollTrigger);

// SMOOTH SCROLLING
const locoScroll = new LocomotiveScroll({
  el: document.querySelector(".scrollContainer"),
  smooth: true
});

locoScroll.on("scroll", ScrollTrigger.update);

ScrollTrigger.scrollerProxy(".scrollContainer", {
  scrollTop(value) {
    return arguments.length ? locoScroll.scrollTo(value, 0, 0) : locoScroll.scroll.instance.scroll.y;
  }, 
  
  getBoundingClientRect() {
    return {top: 0, left: 0, width: window.innerWidth, height: window.innerHeight};
  },
  
  pinType: document.querySelector(".scrollContainer").style.transform ? "transform" : "fixed"
});


  //squeeze hoempage --> bg1
  const timeline = gsap.timeline({
    scrollTrigger: {
      trigger:".bg-wrapper",
      scrub:true,
      start:"top top",
      end:"+=200%"
    }
  });

  timeline
  //homepage squeeze
  .to('#bg',{scaleY:0, transformOrigin:'top'},"same")
  //bg1 expand
  .fromTo('#bg1',{scaleY:0},{scaleY:1, transformOrigin:'bottom'},"same")


  //bg2 3
  const tl2 = gsap.timeline({
    scrollTrigger: {
      trigger:".bg-wrapper",
      scrub:true,
      start:"+=200%",
      end:"+=400%"
    }
  });

tl2
.to('#bg1',{scaleY:0, transformOrigin:'top'},"same2")
.fromTo('#bg2',{scaleY:0},{scaleY:1, transformOrigin:'bottom'},"same2")
.to('#bg2',{scaleY:0, transformOrigin:'top'},"same")
.fromTo('#bg3',{scaleY:0},{scaleY:1, transformOrigin:'bottom'},"same")



//bg4 5
const tl4 = gsap.timeline({
  scrollTrigger: {
    trigger:".bg-wrapper",
    scrub:true,
    start:"+=600%",
    end:"+=400%"
  }
});

tl4
.to('#bg3',{scaleY:0, transformOrigin:'top'},"same2")
.fromTo('#bg4',{scaleY:0},{scaleY:1, transformOrigin:'bottom'},"same2")
.to('#bg4',{scaleY:0, transformOrigin:'top'},"same")
//bg5 expand
.fromTo('#bg5',{scaleY:0},{scaleY:1, transformOrigin:'bottom'},"same")


//bg6 7
const tl6 = gsap.timeline({
  scrollTrigger: {
    trigger:".bg-wrapper",
    scrub:true,
    start:"+=1000%",
    end:"+=400%"
  }
});

tl6
.to('#bg5',{scaleY:0, transformOrigin:'top'},"same2")

.fromTo('#bg6',{scaleY:0},{scaleY:1, transformOrigin:'bottom'},"same2")
  
// keep progress value on window resize
const ST = ScrollTrigger.create({
    trigger:".bg-wrapper",
    start: 0,
    end:"bottom bottom",
    markers:true
  });


  // The relevant part to keeping the progress
  ScrollTrigger.addEventListener("refreshInit", () => progress = ST.progress );
  ScrollTrigger.addEventListener("refresh", () => ST.scroll(progress * ScrollTrigger.maxScroll(window)));

};
// end init funtion


window.addEventListener('load', function(){
    init();
});

// locoScroll
const locoScroll = new LocomotiveScroll();

ScrollTrigger.addEventListener("refresh", () => locoScroll.update());

ScrollTrigger.refresh();
              
            
!
999px

Console