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

              
                <section class="header">
  <div class="intro">
    <div class="inner">
      <h1>An Intro Text</h1>
      <p>This will actually be a slider later on.</p>
    </div>
  </div>

  <div class="cards">
    <div class="card show">
      <h2>Card One</h2>
      <p>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi euismod in pharetra a ultricies in diam. Sed arcu. Cras consequat.</p>
    </div>
    <div class="card">
      <h2>Card Two</h2>
      <p>Praesent dapibus neque id cursus faucibus tortor neque egestas auguae eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi tincidunt quis accumsan porttitor facilisis luctus metus.</p>
      <p>Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
    </div>
    <div class="card">
      <h2>Card Three</h2>
      <p>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam gravida non commodo a sodales sit amet nisi.</p>
    </div>
  </div>
</section>

<section class="additional">
  <h2>Some more Infos</h2>
  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh viverra non semper suscipit posuere a pede.</p>
  <p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque felis.</p>
  <p>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi euismod in pharetra a ultricies in diam. Sed arcu. Cras consequat.</p>
  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
  <p>Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
  <p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
  <p>Suspendisse mauris. Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Integer adipiscing risus a sem. Nullam quis massa sit amet nibh viverra malesuada. Nunc sem lacus, accumsan quis, faucibus non, congue vel, arcu. Ut scelerisque hendrerit tellus. Integer sagittis. Vivamus a mauris eget arcu gravida tristique. Nunc iaculis mi in ante. Vivamus imperdiet nibh feugiat est.</p>
  <p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Integer eu magna sit amet metus fermentum posuere. Morbi sit amet nulla sed dolor elementum imperdiet. Quisque fermentum. Cum sociis natoque penatibus et magnis xdis parturient montes, nascetur ridiculus mus. Pellentesque adipiscing eros ut libero. Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p>
  </p>
</section>
              
            
!

CSS

              
                .header {
  block-size: 100svh;
  display: grid;
  grid-template-areas: "main";
  align-items: center;
  background: url("https://images.unsplash.com/photo-1506452305024-9d3f02d1c9b5?q=80&w=1920&auto=format&fit=crop");
  background-size: cover;
  background-repeat: no-repeat;
  background-color: #333;
}

.intro {
  grid-area: main;
  z-index: 1;
  color: white;
  margin: 2rem;

  .inner {
    max-inline-size: 65ch;
  }
}

/*.cards-wrapper {
  background-color: salmon;
  padding: 2rem;
}*/

.cards {
  margin-inline: 2rem;
  grid-area: main;
  z-index: 2;
  display: grid;
  grid-template-areas: "cards";
  align-items: center;
  background-color: #fff;
  border-radius: 12px;
  padding: 2rem;
  opacity: 1;
  pointer-events: none;
}

.card {
  grid-area: cards;
  z-index: 2;
  opacity: 0;
  pointer-events: none;

  > * {
    max-inline-size: 40ch;
  }

  &.show {
    opacity: 1;
    pointer-events: all;
  }
}

.additional {
  padding: 2rem;
  * {
    max-inline-size: 60ch;
  }
}

/* ------------------
 * Unrelated styling 
 * ------------------ 
 */

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui,
    helvetica neue, Cantarell, Ubuntu, roboto, noto, helvetica, arial,
    sans-serif;
}

h1,
h2,
h3,
h4 {
  margin-block-start: 0;
  margin-block-end: 1.25rem;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

document.addEventListener("DOMContentLoaded", init);

/*
 * Initiate GSAP Timeline
 */
function init() {
  // Define blank timeline
  window.tl = gsap.timeline({
    paused: true,
    onComplete: () => {
      // disable the Observer when the end of the timeline was reached
      console.log("⏳ end of timeline reached, disabling observer...");
      window.observer.disable();
    }
  });
  window.animating = false;

  // Add timeline entries
  window.tl.addLabel("start");

  window.tl.addLabel("hide intro, show card 1");
  window.tl.to(".intro", { opacity: 0, duration: 0.5 });
  window.tl.from(".cards", { translateY: "20vh", opacity: 0, duration: 0.5 });
  window.tl.from(".card:nth-child(1)", { opacity: 0, duration: 1 });

  window.tl.addLabel("showCard2");
  window.tl.to(".card:nth-child(1)", { opacity: 0, duration: 0.5 });
  window.tl.to(".card:nth-child(2)", { opacity: 1, duration: 1 });

  window.tl.addLabel("showCard3");
  window.tl.to(".card:nth-child(2)", { opacity: 0, duration: 0.5 });
  window.tl.to(".card:nth-child(3)", { opacity: 1, duration: 1 });

  window.tl.addLabel("end");

  // An observer listens for scroll wheel or touch eventes and steps through our timeline labels
  window.observer = Observer.create({
    target: ".header", // can be any element (selector text is fine)
    type: "wheel,touch,pointer", // comma-delimited list of what to listen for ("wheel,touch,scroll,pointer")
    wheelSpeed: -1,
    onDown: (self) => tweenToLabel(window.tl.previousLabel(), "down"),
    onUp: (self) => tweenToLabel(window.tl.nextLabel(), "up"),
    tolerance: 10,
    preventDefault: true
  });

  console.log(
    `after init: currentLabel ${window.tl.currentLabel()}, nextLabel ${window.tl.nextLabel()} `
  );
}

/*
 * Go to a label when not already animating
 */
function tweenToLabel(direction, moveDirection) {
  console.log(
    `tween from currentLabel ${window.tl.currentLabel()} -> nextLabel ${direction}`
  );

  if (!window.animating && direction) {
    // Check if we're already animating
    animating = true;
    tl.tweenTo(direction, { onComplete: () => (window.animating = false) });
  }
}

/*
 * Pin the header and reenable Observer when returning
 */
ScrollTrigger.create({
  trigger: ".header",
  pin: true,
  start: "top top",
  end: "+=10",
  onEnterBack: (self) => {
    if (window.observer.isEnabled === false) {
      self.scroll(self.start);
      window.observer.enable();
      tweenToLabel(window.tl.previousLabel());
    }
  }
});

              
            
!
999px

Console