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

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.

HTML

              
                <!-- @TODO: Move away from custom props as the polyfill cant handle that -->
<script src="https://rawcdn.githack.com/flackr/scroll-timeline/637746fa559c3f9d01fcdaf2fcb7e649d18dfc33/dist/scroll-timeline.js" type="module"></script>

<div class="container">
  <section data-bgcolor="#bcb8ad" data-textcolor="#032f35">
    <div>
      <h1 data-scroll data-scroll-speed="1"><span>Horizontal</span> <span>scroll</span> <span>section</span></h1>
      <p data-scroll data-scroll-speed="2" data-scroll-delay="0.2">With CSS ScrollTimeline</p>
    </div>

  </section>

  <section id="sectionPin">
    <div class="pin-wrap">
      <h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</h2>
      <img src="https://images.pexels.com/photos/5207262/pexels-photo-5207262.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=900" alt="">
      <img src="https://images.pexels.com/photos/3371358/pexels-photo-3371358.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=900" alt="">
      <img src="https://images.pexels.com/photos/3618545/pexels-photo-3618545.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=900" alt="">

    </div>
  </section>
  <section data-bgcolor="#e3857a" data-textcolor="#f1dba7"><img src="https://images.pexels.com/photos/4791474/pexels-photo-4791474.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="">
    <h2 data-scroll data-scroll-speed="1" class="credit">
		Created by <a href="https://twitter.com/bramus" target="_top" rel="noreferrer noopener">Bramus</a>.<br /><br />Design and content by <a href="https://codepen.io/cameronknight/pen/qBNvrRQ" target="_top">Cameron Knight</a>.</h2>
  </section>
</div>

<div class="warning">⚠ Your browser does not support CSS Scroll-Linked Animations, so this demo won't work. If you're feeling adventurous use Chrome 89 with “Experimental Web Platform Features” enabled. Alternatively you can <a href="https://twitter.com/bramus/status/1356589270379724802" target="_top">watch a recording of this demo in action</a> or <a href="https://codepen.io/bramus/pen/jOVWpyr" target="_top" rel="noreferrer noopener">check out a JS version</a>.</div>
              
            
!

CSS

              
                /* Right below is the original CSS from https://codepen.io/cameronknight/pen/qBNvrRQ
 * Scroll down to see the extra CSS Additions to implement is using CSS @scroll-timeline
 */
:root {
  --text-color: #111;
  --bg-color: #b9b3a9;
}

body {
  font-family: termina, sans-serif;
  color: var(--text-color);
  background: var(--bg-color);
  transition: 0.3s ease-out;
  overflow-x: hidden;
  max-width: 100%;
  width: 100%;
  overscroll-behavior: none;
}

section {
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
}

section:not(#sectionPin) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  grid-gap: 2rem;
  padding: 50px 10vw;
  margin: auto;
  place-items: center;
}

img {
  height: 80vh;
  width: auto;
  object-fit: cover;
}

h1 {
  font-size: 5rem;
  line-height: 1;
  font-weight: 800;
  margin-bottom: 1rem;
  position: absolute;
  top: 10vw;
  left: 10vw;
  z-index: 4;
  overflow-wrap: break-word;
  hyphens: auto;

  @media (max-width: 768px) {
    font-size: 16vw;
  }

  span {
    display: block;
  }
}

h2 {
  font-size: 2rem;
  max-width: 400px;
}

.credit {
  font-family: Termina, sans-serif;
  a {
    color: var(--text-color);
  }
}

* {
  box-sizing: border-box;
}

#sectionPin {
  height: 100vh;
  overflow: hidden;
  display: flex;
  left: 0;
  background: var(--text-color);
  color: var(--bg-color);
}

.pin-wrap {
  height: 100vh;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 50px 10vw;

  & > * {
    min-width: 60vw;
    padding: 0 5vw;
  }
}

p {
  position: absolute;
  bottom: 10vw;
  right: 10vw;
  width: 200px;
  line-height: 1.5;
}













/* CSS Additions by Bramus */

/* Show warning for older browser */
.warning {
  position: fixed;
  top: 1em;
  right: 1em;
  left: 1em;
	padding: 1em;
	border: 1px solid black;
  z-index: 9999;
  text-align: center;
  color: black;
  background: rgba(255 255 225 / 0.9);
}

.warning a {
  color: blue;
}

@supports (animation-timeline: works) {
  
  /* Hide Warning */
  .warning {
    display: none;
  }
  
  
  /* Move the horizontal scrolling section as we #sectionPin enters and leaves the viewport  */
  :root {
    --sections-individual-size: 100vh;
    --sections-pinned-size: 5;
  }
  
  @scroll-timeline horizontal-section-scrolling-into-view {
    source: selector(body);

		scroll-offsets:
      /* Start when #sectionPin touches the top edge of the scrollport and is visible inside the scrollport */
      selector(#sectionPin) start 1,
      /* End when #sectionPin touches the bottom edge of the scrollport and is visible inside the scrollport */
		  selector(#sectionPin) end 1
    ;
		start: selector(#sectionPin) start 1;
		end: selector(#sectionPin) end 1;

    time-range: 1s;
  }

  @keyframes move-horizontal-scrolling-section {
    to {
      transform: translateX(calc(-100% + 100vw)); /* Move horizontally so that right edge is aligned against the viewport */
    }
  }
  
  #sectionPin {
    height: calc(var(--sections-pinned-size) * var(--sections-individual-size)); /* Stretch it out, so that we create room for the horizontal scroll animation */
    overflow: visible; /* To make position sticky work 
 */
  }
  
  .pin-wrap {
    /* Stick to Top */
    height: var(--sections-individual-size);
    position: sticky;
    top: 0;
    
    /* Move to right using animation timeline*/
    will-change: transform;
    animation: 1s linear move-horizontal-scrolling-section forwards;
    animation-timeline: horizontal-section-scrolling-into-view;
  }
  
  
  
  /* Parallax Effects for other components*/
  :root {
    --sections-total-size: calc(2 + var(--sections-pinned-size));
    --sections-total-height: calc(var(--sections-total-size) * var(--sections-individual-size));
    
    --duration: 1s;
    
    --single-section-duration: calc(var(--duration) / var(--sections-total-size));
    --horizontal-section-duration: calc(var(--single-section-duration) * var(--sections-pinned-size));
    --last-section-delay: calc(var(--duration) / var(--sections-total-size) * calc(var(--sections-total-size) - 1));
  }
  
  
  /* Main Body Scroll Timeline */
  @scroll-timeline scrolling {
    source: selector(body);
    scroll-offsets: 0, 100%;
    start: 0;
    end: 100%;
    time-range: 1s;
  }

  /* Move the title up as we scroll through the first screen */
  @keyframes move-title {
    to {
      transform: translateY(-10vh);
    }
  }
  h1 {
    animation: var(--single-section-duration) linear move-title forwards;
    animation-timeline: scrolling;
  }

  /* Move the tagline up as we scroll through the first screen */
  @keyframes move-tagline {
    to {
      transform: translateY(-20vh);
    }
  }
  p {
    animation: var(--single-section-duration) linear move-tagline forwards;
    animation-timeline: scrolling;
  }
  
  /* Move the credit up as we scroll through the last screen */
  @keyframes move-credit {
    from {
      transform: translateY(10vh);
    }
    to {
      transform: translateY(-20vh);
    }
  }
  .credit {
    animation: var(--single-section-duration) linear move-credit var(--last-section-delay) forwards;
    animation-timeline: scrolling;
  }
}
              
            
!

JS

              
                // Alternative Versions:

// - CSS view-timeline 2022 + Polyfill: https://codepen.io/bramus/pen/dyeVmvg 
// - JS ScrollTimeline 2022 Syntax + Polyfill: https://codepen.io/bramus/pen/WNzZmdP
// - JS Motion One: https://codepen.io/bramus/pen/MWVvrEE
// - CSS @scroll-timeline: https://codepen.io/bramus/pen/QWGbOBQ 👈 = The version you are currently looking at
// - JS ScrollTimeline 2021 Syntax: https://codepen.io/bramus/pen/jOVWpyr
              
            
!
999px

Console