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

              
                <div class="content">
  <div id="container">
    <div class="module green"></div>
    <div class="module yellow">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module purple">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module orange">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module blue">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module red">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module purple">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module orange">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module blue">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
    <div class="module red">
      <div class="child">
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
        <p>content goes here</p>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                html,
body {
  padding: 0;
  margin: 0;
  overflow-x: hidden;
}
body {
  /*   overflow-x: hidden; */
}

.content {
  height: 100vh;
}

#container {
  background-color: grey;
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  height: 100vh;
}

.module {
  height: 100%;
  display: flex;
  overflow: hidden;
}
.module.active {
  overflow: visible;
}
.green {
  width: 700px;
  background-color: green;
}

.yellow {
  width: 100px;
  background-color: yellow;
}

.purple {
  width: 100px;
  background-color: purple;
}

.orange {
  width: 100px;
  background-color: purple;
}

.blue {
  width: 100px;
  background-color: blue;
}

.red {
  width: 100px;
  background-color: red;
}
.yellow.active,
.purple.active,
.orange.active,
.blue.active,
.red.active {
  width: auto;
}
.child {
  display: flex;
  width: auto;
  margin-left: 120px;
}

              
            
!

JS

              
                console.clear();

gsap.registerPlugin(ScrollTrigger, Flip);

let container = document.getElementById("container");

$(".module").on("click", function (e) {
  let x = gsap.getProperty(container, "x"),
      st = tween.scrollTrigger,
      state = Flip.getState(this);
  $(this).toggleClass("active");
  e.preventDefault();
  Flip.from(state, {
    duration: 1,
    onUpdate: () => {
      let progress = Math.abs(x / (container.scrollWidth - document.documentElement.clientWidth));
      st.refresh(); // recalculates start/end
      st.scroll(st.start + progress * (st.end - st.start)); // scroll to the spot where the x position of the container matches where it was originally
      st.update(); // since we've got a scrub, we need to trigger it here so we can then jump to the end (skip the scrub) during this transition
      let scrub = st.getTween();
      scrub && scrub.progress(1); // jump to the end of the scrub.
    }
  });
});
const tween = gsap.to(container, {
  x: () => -(container.scrollWidth - document.documentElement.clientWidth) + "px",
  ease: "none",
  scrollTrigger: {
    trigger: ".content",
    pin: true,
    scrub: 1,
    end: () => "+=" + container.scrollWidth,
    invalidateOnRefresh: true
  }
});

              
            
!
999px

Console