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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <header>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
  </p>
</header>

<div class="accordion">
  <div class="drawer">
    <a href="#drawer1" class="drawer_title">Drawer 1<span class="plus"></span></a>
    <div class="drawer_content drawer_content_first">
      <p>Nullam id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Donec id elit non mi porta gravida at eget metus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.</p>
    </div>
  </div>
  <div class="drawer">
    <a href="#drawer2" class="drawer_title">Drawer 2<span class="plus"></span></a>
    <div class="drawer_content">
      <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros..</p>
    </div>
  </div>
  <div class="drawer drawer_last">
    <a href="#drawer3" class="drawer_title">Drawer 3<span class="plus"></span></a>
    <div class="drawer_content drawer_content_last">
      <p>Nullam id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Donec id elit non mi porta gravida at eget metus. </p>
    </div>
  </div>
</div>

<footer>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
  </p>
</footer>
              
            
!

CSS

              
                :root {
  font: 20px system-ui;
  @media screen and (max-width: 1000px), screen and (max-height: 600px) {
    font-size: 16px;
  }
}

body {
  line-height: 1.5;
  background: #faf3e0;
  color: #1e212d;
}

.accordion {
  padding: 1rem;
  max-width: 30rem;
  margin: 0 auto;
  box-sizing: border-box;
}

.drawer {
  &_title {
    display: flex;
    color: inherit;
    text-decoration: none;
    background: #1e212d;
    color: #faf3e0;
    padding: 1rem;
    justify-content: space-between;
  }
  &_content {
    overflow: hidden;
    height: 100vw;
  }
}

header,
footer {
  p {
    margin: 1rem;
  }
}

              
            
!

JS

              
                // Setting up some defaults
gsap.defaults({
  duration: 1,
  ease: "power1.inOut"
});

const drawers = document.querySelectorAll(".drawer");

// Body height = drawers count * 100vh
gsap.set(document.body, {
  height: (drawers.length + 1) * 100 + "vh"
});

// Pin the accordion
ScrollTrigger.create({
  trigger: ".accordion",
  pin: true,
  start: "top top",
  end: "bottom bottom",
  endTrigger: "body",
  invalidateOnRefresh: true
});

drawers.forEach((drawer, i) => {
  if (i < drawers.length - 1) {
    const drawer_content = drawer.querySelector(".drawer_content");

    // Setting up a timeline for every drawer
    drawer.tl = gsap.timeline({
      scrollTrigger: {
        scrub: 1,
        invalidateOnRefresh: true,
        start: () => window.innerHeight * i,
        end: () => window.innerHeight * (i + 1)
      }
    });

    // Animate the drawer content to auto height
    drawer.tl.to(drawer_content, {
      height: "auto",
      autoAlpha: 1
    });

    // Animate the drawer content to 0 height
    drawer.tl.to(drawer_content, {
      height: 0
    });
  }
});

const drawer_last = document.querySelector(".drawer_content_last");
// Setting up a timeline for every drawer
drawer_last.tl = gsap.timeline({
  scrollTrigger: {
    scrub: 1,
    invalidateOnRefresh: true,
    start: "top top",
    end: "bottom bottom"
  }
});

// Animate the drawer content to auto height
drawer_last.tl.to(drawer_last, {
  height: "auto",
  autoAlpha: 1
});

// Animate the drawer content to 0 height
drawer_last.tl.to(drawer_last, {
  height: 0
});

drawer_last.tl.to(".accordion", {
  height: "800px"
});

gsap.set(document.body, {
  height: drawers.length * 100 + "vh"
});

//gsap.set("footer", { marginTop: "-=800" });

//gsap.set("body", { height: "800" });

              
            
!
999px

Console