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

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 id="main">

    <section>
      <div class="panel orange">
      </div>
    </section>

    <section>
      <div class="panel blue">
      </div>
    </section>
    
    <section class="container">

      <div class="panel red">
        <div class="inner"> </div>
      </div>

      <div class="panel green">
        <div class="inner"> </div>
      </div>

      <div class="panel red">
        <div class="inner"> </div>
      </div>

  </section>
    
    
  <section>
    <div class="panel orange">
    </div>
  </section>
    
  <section>
    <div class="panel blue">
    </div>
  </section>
  </div>

              
            
!

CSS

              
                #main{
  overflow:hidden;

}

section{
	height: 100vh;
  width:100vw;
}

.container{
  position: relative;
  display:flex;
  flex-direction:row;
  width: 100vw;
  height: 100vh;
  overflow:hidden;
}

.panel{
  width: 100vw;
  height:100%;
  display: flex;
}

.inner{
 width:100vw;
 display: flex;
 justify-content: center;
}


.orange{
  background-color:#FFB433;
}
.blue{
  background-color:#8F8FB5;
}
.green{
  background-color:green;
}
.red{
   background-color:#FF4545;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

/*-- ScrollTrigger 1: sections scroll and snap vertically ------*/

let sections = gsap.utils.toArray('section');
let snap = value => value; // a snapping function that we'll set later in a "refresh" event listener because we need all the ScrollTrigger positions to get calculated first

// this ScrollTrigger covers the entire page and is just for snapping logic
ScrollTrigger.create({
    start: 0,
    end: "max",
    snap: {
        snapTo: (value, self) => snap(value, self.direction),
        duration: {min: 0.2, max: 0.4},
        delay: 0,
    }
});

/*---ScrollTrigger 2: horizontal scroll in section ".container" --*/

let panels = gsap.utils.toArray(".container .panel");
 
let panelTween = gsap.to(panels, {
  xPercent: -100 * (panels.length - 1),
  ease: "none",
  scrollTrigger: {
    trigger: ".container",
    start: "top top",
    end: "+=" + (innerWidth * 3),
    markers: true,
    pin: true,
    scrub: 1,
  }
});

// we create a ScrollTrigger for each section just so we can figure out where they're positioned (when their top hits the top of the viewport)
let sectionTriggers = sections.map(section => ScrollTrigger.create({
  trigger: section,
  start: "top top",
  refreshPriority: -1 // just so they get calculated last
}));

// after ScrollTrigger refreshes, we create a snap function that's directional. 
ScrollTrigger.addEventListener("refresh", () => {
  let start = panelTween.scrollTrigger.start,
      end = panelTween.scrollTrigger.end,
      each = (end - start) / (panels.length - 1), // each panel takes up a certain distance
      max = ScrollTrigger.maxScroll(window),
      sectionPositions = sectionTriggers.map(trigger => trigger.start / max); // snapping values must be in ratios (between 0 and 1)
  panels.forEach((panel, i) => sectionPositions.push((start + i * each) / max)); // add the panel positions
  snap = ScrollTrigger.snapDirectional(sectionPositions); // a snapping function that we can just feed a scroll value to and a direction and it'll spit back the closest one (ratio/progress) in that direction
});
              
            
!
999px

Console