Pen Settings



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


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


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.


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.


                <section class="header">

<section id="scroll-contianer">
  <ul class="scroll-nav">
    <li><a class="anchor active blah" href="#panel-1">Panel #1</a></li>
    <li><a class="anchor" href="#panel-2">Panel #2</a></li>
    <li><a class="anchor" href="#panel-3">Panel #3</a></li>
    <li><a class="anchor" href="#panel-4">Panel #4</a></li>
  <div id="panel-1" class="scroll-panel" style="background-color: red;">
    <h2>Panel #1</h2>
  <div id="panel-2" class="scroll-panel" style="background-color: green;">
    <h2>Panel #2</h2>
  <div id="panel-3" class="scroll-panel" style="background-color: blue;">
    <h2>Panel #3</h2>
  <div id="panel-4" class="scroll-panel" style="background-color: orange;">
    <h2>Panel #4</h2>

<section class="footer">


                * {
  font-family: sans-serif;
  box-sizing: border-box;
  padding: 0;
  margin: 0;

body {
  overflow-x: hidden;

h1 {
  color: #000000;
  font-size: 50px;
  text-transform: uppercase;

h2 {
  color: #ffffff;
  font-size: 30px;
  text-transform: uppercase;

section {
  display: flex;
  width: 100%;
  height: 100vh;

section.header {
  background-color: #eeeeee;
  align-items: center;
  justify-content: center;

section.footer {
  background-color: #777777;
  align-items: center;
  justify-content: center;

#scroll-contianer {
  position: relative;
  background-color: #7CC7B8;

.scroll-panel {
  display: flex;
  width: 100vw;
  height: 100vh;
  flex: 0 0 auto;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  z-index: 1;

.scroll-panel.blank {
  width: 25vw;

.scroll-panel h2 {
  transition: opacity ease-in-out 250ms;
} h2 {
  color: yellow;
  opacity: 1;
  transition: opacity ease-in-out 250ms;

ul.scroll-nav {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: 40px;
  transform: translate(-40px, -50%);
  list-style-type: none;

ul.scroll-nav li {
  margin: 10px 0;

ul.scroll-nav li a {
  color: #ffffff;
  text-decoration: none;
  transition: color ease-in-out 250ms;

ul.scroll-nav li, ul.scroll-nav li a:hover {
  color: yellow;


                gsap.registerPlugin(ScrollToPlugin, ScrollTrigger)

let scrollContainer = document.getElementById('scroll-contianer'),
    sections = gsap.utils.toArray(".scroll-panel"),
    navLinks = gsap.utils.toArray(".scroll-nav li a"),
    maxWidth = 0

const getMaxWidth = () => {
  maxWidth = 0;
  sections.forEach((section) => {
    maxWidth += section.offsetWidth

ScrollTrigger.addEventListener("refreshInit", getMaxWidth)

let horizontalScroll =, {
  x: () => `-${maxWidth - window.innerWidth}`,
  ease: 'none',
  scrollTrigger: {
    trigger: scrollContainer,
    pin: true,
    scrub: 1,
    end: () => `+=${maxWidth}`,
    invalidateOnRefresh: true,
    markers: true

let getPosition = getScrollLookup(".scroll-panel", horizontalScroll, "center center");

navLinks.forEach((el, i) => {
  // handles toggling the "active" class of the nav link when the corresponding section's left edge hits the center and then toggle it off when the right edge hits the center.
    containerAnimation: horizontalScroll,
    trigger: sections[i], 
    start: "left center",
    end: "right center",
    // the following line is to work around a minor bug that'll be fixed in the release following 3.10.4
    onRefresh: self => self.progress && self.progress < 1 && el.classList.add("active"),
    toggleClass: {targets: el, className: "active"}
  // nav link click handling (scroll)
  el.addEventListener("click", e => {
    e.preventDefault();, {
      scrollTo: getPosition(el.getAttribute("href")),
      overwrite: "auto",
      duration: 1

function getScrollLookup(targets, containerAnimation, position) {
  let triggers = gsap.utils.toArray(targets).map((section, nav) => ScrollTrigger.create({
        trigger: section,
        start: position || "left left",
        containerAnimation: containerAnimation,
      st = containerAnimation.scrollTrigger;
  return target => {
    let t = gsap.utils.toArray(target)[0],
        i = triggers.length
    while (i-- && triggers[i].trigger !== t) {}
    return i >= 0 ? st.start + (triggers[i].start / containerAnimation.duration()) * (st.end - st.start) : console.warn("target not found", target)