Pen Settings



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


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.


<div class="container">
  <div class="description panel blue">
      <div class="scroll-down"><div class="arrow"></div></div>

  <section class="panel red">
  <section class="panel orange">
  <section class="panel purple">

<button>Add section</button>



                html {
	overflow-y: scroll;
	height: 100%;
	-webkit-overflow-scrolling: touch;
	overflow-scrolling: touch;
body {
	overflow-y: visible;
	position: relative;
  height: unset;
html, body {
	overflow-x: hidden;
	margin: 0;

.container {
  --width: 400%;
	width: var(--width);
	height: 100vh;
	display: flex;
	flex-wrap: nowrap;

.firstContainer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: yellow;

.lastContainer {
  display: flex;
  height: 100vh;
  background: yellow;

.panel {
  min-width: 100vw!important;
button {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);



let container = document.querySelector('.container');
let sections = gsap.utils.toArray(".panel");
let getRandomColor = gsap.utils.random("red,blue,orange,purple".split(","), true);

let scrollTween ='.container', {
  x: () => -(container.scrollWidth - document.documentElement.clientWidth) + "px",
  ease: "none",
  scrollTrigger: {
    trigger: container,
    pin: true,
    scrub: 1,
    end: () => "+=" + container.offsetWidth,
    invalidateOnRefresh: true,

const addSection = () => {
  const sectionEl = document.createElement("section");
  sectionEl.classList.add('panel', getRandomColor());
  sectionEl.textContent = "New section " + sections.length;
  const st = scrollTween.scrollTrigger,
        oldProgress = st.progress;
  // we use a CSS variable because when you pin something with ScrollTrigger, it must record the width/height initially and then revert that when refreshing, thus if we directly set the width inline, it'll be lost during refresh().
  gsap.set(container, { "--width": (sections.length * 100) + "%" });
  // update scrolltrigger
  // adjust the scroll position according to the previous ratio to make it appear seamless even though the ratios changed
  st.scroll(st.start + (st.end - st.start) * oldProgress * (sections.length - 2) / (sections.length - 1));
  st.update(); // don't wait for the scroll event to trigger the scrub animation - force it immediately so we can force it to the end
  st.endAnimation(); // get rid of the scrub animation to the new scroll position (to make it look seamless)

document.querySelector('button').addEventListener('click', addSection);