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

              
                <!-- fake body -->

<body class="overflow-x-hidden font-semibold text-white text-5xl" style="font-family:'Open Sans';">
  <!-- fake body -->
  <!-- start sections // -->
  <section class="bg-red-600 min-h-screen flex items-center justify-center">A</section>
  <section class="bg-blue-600 min-h-screen flex items-center justify-center">B</section>
  <!-- horizonal scrolling section / -->
  <section class="bg-yellow-600 min-h-screen w-[500%] flex flex-no-wrap st--horizontal">
    <!-- section w up and down elements -->
    <div class="w-screen bg-purple-900 min-h-screen relative flex justify-center st--section-c">
      <!-- odd -->
      <div class="h-1/2 w-1/4 flex items-center justify-center bg-white text-black st--piston-odd">Y</div>
      <!-- even -->
      <div class="h-1/2 w-1/4 flex items-center justify-center top-auto bottom-0 self-end bg-black st--piston-even">E</div>
      <!-- odd -->
      <div class="h-1/2 w-1/4 flex items-center justify-center bg-white text-black st--piston-odd">A</div>
      <!-- even -->
      <div class="h-1/2 w-1/4 flex items-center justify-center top-auto bottom-0 self-end bg-black st--piston-even">H</div>
      <!-- -->
    </div>
    <!-- end -->
    <!-- section c2: pattern down -->
    <div class="w-screen bg-purple-800 min-h-screen flex items-center justify-center relative st--section-c2">
      <img src="https://kubikdesign.com.au/codepen/pattern.svg" class="st--pattern w-full absolute z-1 bottom-0 left-0">
      <div class="leading-none text-8xl">HELL<br>YEAH</div>
    </div>
    <!-- section c3: attempting to move c3 from top left to top right, then top right to bottom right -->
    <div class="w-screen bg-purple-700 min-h-screen flex items-center justify-center relative st--section-c3">
      <div class="absolute left-0 top-0 z-10 h-[80px] w-[80px] bg-black flex items-center justify-center text-20px text-white st--block-c3">3</div>
    </div>
    <!-- -->
    <div class="w-screen bg-purple-600 min-h-screen flex items-center justify-center">4</div>
    <div class="w-screen bg-purple-500 min-h-screen flex items-center justify-center">5</div>
  </section>
  <!-- end / -->
  <section class="bg-pink-600 min-h-screen flex items-center justify-center">D</section>
  <section class="bg-green-600 min-h-screen flex items-center justify-center">E</section>
  <!-- end sections // -->
  <!-- fake body -->
</body>
<!-- fake body -->
              
            
!

CSS

              
                .st--block-c3 {
  z-index: 999
}

.bg-purple-600 {
  position: relative;
  z-index: -1
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

let sections = gsap.utils.toArray(".st--horizontal > div");
let scrollTween = gsap.to(sections, {
  xPercent: -100 * (sections.length - 1),
  ease: "none",
  scrollTrigger: {
    trigger: ".st--horizontal",
    pin: true,
    scrub: 1,
    snap: 1 / (sections.length - 1),
    // base vertical scrolling on how wide the container is so it feels more natural
    end: () => "+=" + document.querySelector(".st--horizontal").offsetWidth
  }
});

gsap.to(".st--piston-even, .st--piston-odd", {
  // odd goes -100%, even goes 100%
  y: (i) => (i % 2 ? "-100%" : "100%"),
  ease: "none",
  yoyo: true,
  repeat: 2,
  scrollTrigger: {
    trigger: ".st--section-c",
    containerAnimation: scrollTween,
    start: "left left",
    scrub: true
    // markers: true,
    // id: 'piston--odd',
  }
});

gsap.to(".st--pattern", {
  // v1
  yPercent: 50,
  ease: "none",
  scrollTrigger: {
    trigger: ".st--section-c2",
    containerAnimation: scrollTween,
    // start: 'left left',
    start: () =>
      "-=" + document.querySelector(".st--section-c2").offsetWidth + " left",
    end: () => "+=" + document.querySelector(".st--section-c2").offsetWidth * 2,
    scrub: true
  }
});

// attempting to move c3 from top left to top right, then top right to bottom right
var tl = gsap.timeline({
    scrollTrigger: {
        trigger: '.st--section-c3',
        containerAnimation: scrollTween,
        invalidateOnRefresh: true,
        scrub: true,
        start: 'left left',
        end: 'right left',
        markers: true,
        id: 'timeline'
    },
})

tl.to('.st--block-c3', {
    ease: 'none',
    x: () => document.querySelector('.st--section-c3').offsetWidth * 1.4,
}).to('.st--block-c3', {
    ease: 'none',
    y: () => document.querySelector('.st--section-c3').offsetHeight - 75,
    x: () => `-=${(document.querySelector('.st--section-c3').offsetWidth / 2) - 75}`,
})
              
            
!
999px

Console