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

              
                

<div class="swipe-section">
  <section class="panel red">
    ScrollTrigger.observe() section
  </section>
  <section class="panel purple x-100">
        <button>click me to unhide  vertical scroll section</button>
    Button to expand this section to vertical scroll, then at the end of the vertical scroll, the next section slides over. But after section 3 slides over it hides the vertical scroll so that if you scroll back from section 3 to this purple section 2 it just slides back to the top of section 2.  </section>
  <section class="panel blue x-100">
     Section 3
  </section>
  <section class="panel orange x-100">
      Section 4
   </section>
</div>



              
            
!

CSS

              
                body {
  overscroll-behavior: none;
  height: 100vh;
}

.swipe-section {
  position: relative;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.swipe-section .panel {
  position: absolute;
}

.vh-200 {
  height: 200vh !important!
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

// Gsap Code
let currentIndex = 0;
let animating;
let swipePanels = gsap.utils.toArray(".swipe-section .panel");

// set second panel two initial 100%
gsap.set(".x-100", {xPercent: 100});

// set z-index levels for the swipe panels
let reversedPanels = [...swipePanels];
reversedPanels.forEach((panel, index) => {
  gsap.set(panel, { zIndex: index });
});

// create an observer and disable it to start
let intentObserver = ScrollTrigger.observe({
  type: "wheel,touch",
  onUp: () => !animating && gotoPanel(currentIndex - 1, false),
  onDown: () => !animating && gotoPanel(currentIndex + 1, true),
  tolerance: 10,
  preventDefault: true
})
intentObserver.disable();

// handle the panel swipe animations
function gotoPanel(index, isScrollingDown) {
  animating = true;
  // return to normal scroll if we're at the end or back up to the start
  if ((index === swipePanels.length && isScrollingDown) || (index === -1 && !isScrollingDown)) {

        let target = index;
        gsap.to(target, {
        // xPercent: isScrollingDown ? -100 : 0,
        duration: 0.00,
        onComplete: () => (animating = false)
    });
    return
  }

//   target the second panel, last panel?
  let target = isScrollingDown ?  swipePanels[index]: swipePanels[currentIndex];

  gsap.to(target, {
    xPercent: isScrollingDown ? 0 : 100,
    duration: 0.75,
    onComplete: () => (animating = false)
  });

  currentIndex = index;
  console.log(index);

}

// pin swipe section and initiate observer
ScrollTrigger.create({
  trigger: ".swipe-section",
  pin: true,
  start: "top top",
  onEnter: () => {
    intentObserver.enable();
    gotoPanel(currentIndex + 1, true);

    
  },
  onEnterBack: () => {
    intentObserver.enable();
    gotoPanel(currentIndex - 1, false);
  }
})

// make sure scrolltrigger doesnt fire onLoad
let hasScrolled = false;
function checkIfScrolled() {
  if(!hasScrolled) {
    queuedAnims.push(this.parent.pause(0));
  }
}


              
            
!
999px

Console