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 -->

  <!-- section a: blank -->
  <section class="bg-red-600 min-h-screen flex items-center justify-center">A</section>
  <!-- section b: animate b simple -->
  <section class="bg-blue-600 min-h-screen flex items-center justify-center relative st--section-b">
    <div class="absolute left-0 top-0 h-[30px] w-[30px] bg-white flex items-center justify-center st--block-b text-xl text-black">B</div>
  </section>

  <!-- horizontal scolling -->
  <section class="bg-yellow-600 min-h-screen w-[500%] flex flex-no-wrap st--horizontal">
    <!-- section c1: yeah up + down -->
    <div class="w-screen bg-purple-900 min-h-screen relative flex justify-center st--section-c1">
      <div class="h-1/2 w-1/4 flex items-center justify-center bg-black st--piston-odd">Y</div>
      <div class="h-1/2 w-1/4 flex items-center justify-center top-auto bottom-0 self-end bg-white text-black st--piston-even">E</div>
      <div class="h-1/2 w-1/4 flex items-center justify-center bg-black st--piston-odd">A</div>
      <div class="h-1/2 w-1/4 flex items-center justify-center top-auto bottom-0 self-end bg-white text-black st--piston-even">H</div>
    </div>
    <!-- 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: moving block around corners -->
    <div class="w-screen bg-purple-700 min-h-screen relative st--section-c3">
      <div class="absolute left-0 bottom-0 z-10 h-[150px] w-[150px] rounded-full bg-red-600 flex items-center justify-center text-xl text-white st--block-c3">3</div>
    </div>
    <!-- section c4: bg color change -->
    <div class="w-screen bg-black min-h-screen flex items-center justify-center relative st--section-c4">
      <img src="https://kubikdesign.com.au/codepen/bg-letters.svg" class="absolute inset-0 z-0 w-full h-full object-contain st--block-c4">
    </div>
    <!-- blank -->
    <div class="w-screen bg-purple-500 min-h-screen flex items-center justify-center">5</div>
    <!-- end -->
  </section>
  <!-- end: horizontal scolling -->

  <!-- blank sections -->
  <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>

  <!-- fake body -->
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                // function: generate random color
function randomColor() {
    var m = new Array()
    for (var i = 0; i < 80; i++) {
        m.push(
            '#' +
                Math.floor(Math.random() * 10) +
                Math.floor(Math.random() * 10) +
                Math.floor(Math.random() * 10)
        ) // to construct a color arrary.
    }
    return m
}

// function: generate random linear gradient
function createHex() {
    var hexCode1 = ''
    var hexValues1 = '0123456789abcdef'

    for (var i = 0; i < 6; i++) {
        hexCode1 += hexValues1.charAt(
            Math.floor(Math.random() * hexValues1.length)
        )
    }
    return hexCode1
}
function generate() {
    var deg = Math.floor(Math.random() * 360)
    var gradient =
        'linear-gradient(' +
        deg +
        'deg, ' +
        '#' +
        createHex() +
        ', ' +
        '#' +
        createHex() +
        ')'
    return gradient
}

// register scrollTrigger
gsap.registerPlugin(ScrollTrigger)

// horizontal scrolling
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,
    },
})

// animate block b simple
gsap.to('.st--block-b', {
    // x: document.querySelector('.st--section-b').offsetWidth,
    y: () => document.querySelector('.st--section-b').offsetHeight,
    rotation: 360,
    ease: 'none',
    scrollTrigger: {
        trigger: '.st--section-b',
        start: 'top top', // when the top of the trigger hits the top of the viewport
        end: 'bottom top',
        scrub: true, // use value for a delayed effect
    },
})

// https://greensock.com/forums/topic/35004-gsap3-scrolltrigger-scrub-enabled-move-element-up-and-then-down/
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-c1',
        containerAnimation: scrollTween,
        start: 'left left',
        scrub: true,
    },
})

// section c2: pattern overlay down
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,
    },
})

// section c3: moving colour changing block
var tl = gsap.timeline({
    scrollTrigger: {
        trigger: '.st--section-c3',
        containerAnimation: scrollTween,
        scrub: true,
        start: () =>
            '-=' +
            document.querySelector('.st--section-c3').offsetWidth / 2 +
            ' left',
        end: () => '+=' + document.querySelector('.st--section-c3').offsetWidth,
    },
})

// section c3: moving block
tl.to('.st--block-c3', {
    ease: 'none',
    y: () =>
        -document.querySelector('.st--section-c3').offsetHeight +
        document.querySelector('.st--block-c3').offsetHeight,
})
    .to('.st--block-c3', {
        ease: 'none',
        x: () =>
            document.querySelector('.st--section-c3').offsetWidth -
            document.querySelector('.st--block-c3').offsetWidth,
    })
    .to('.st--block-c3', {
        ease: 'none',
        y: () => 0,
    })
    .to('.st--block-c3', {
        ease: 'none',
        x: () =>
            document.querySelector('.st--section-c3').offsetWidth * 0.5 -
            document.querySelector('.st--block-c3').offsetWidth,
    })

// section c3: changing block colour
var tlColor = gsap.timeline({
    scrollTrigger: {
        trigger: '.st--section-c3',
        containerAnimation: scrollTween,
        scrub: true,
        start: () =>
            '-=' +
            document.querySelector('.st--section-c3').offsetWidth / 2 +
            ' left',
        end: () => '+=' + document.querySelector('.st--section-c3').offsetWidth,
    },
})
tlColor
    .to('.st--block-c3', {
        ease: 'none',
        backgroundColor: randomColor,
    })
    .to('.st--block-c3', {
        ease: 'none',
        backgroundColor: randomColor,
    })
    .to('.st--block-c3', {
        ease: 'none',
        backgroundColor: randomColor,
    })
    .to('.st--block-c3', {
        ease: 'none',
        backgroundColor: randomColor,
    })
    .to('.st--block-c3', {
        ease: 'none',
        backgroundColor: randomColor,
    })
    .to('.st--block-c3', {
        ease: 'none',
        backgroundColor: randomColor,
    })

// section c4: background image colour change
var tlBackgroundColor = gsap.timeline({
    scrollTrigger: {
        trigger: '.st--section-c4',
        containerAnimation: scrollTween,
        scrub: true,
        // markers: true,
        // start: 'left left',
        start: () =>
            '-=' +
            document.querySelector('.st--section-c4').offsetWidth +
            ' left',
        end: () =>
            '+=' + document.querySelector('.st--section-c4').offsetWidth * 2,
    },
})
tlBackgroundColor
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })
    .to('.st--block-c4', {
        ease: 'none',
        backgroundImage: generate,
    })

              
            
!
999px

Console