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="text-container">
  <span class="text text1">
   One  
  </span>
  <span class="text text2">
   Two
  </span>
  <span class="text text3">
   Three
  </span>
</div>


              
            
!

CSS

              
                body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  
}
@font-face {
    font-family: 'Monument';
    src: url('https://assets.codepen.io/4086427/MonumentExtended-Bold.otf');
 }
@font-face {
    font-family: 'Rational';
    src: url('https://assets.codepen.io/4086427/Rene+Bieder+-+RationalDisplayDEMO-SemiBold.otf');
 }
@font-face {
    font-family: 'Rational-light';
    src: url('https://assets.codepen.io/4086427/RationalDisplay-Light.otf');
 }

.text-container {
  position: static;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 20vh;
  width: 100%;
  /*background-color: blue;*/
}
.text {
  position: absolute;
  top: 0;
  font-family:"Monument";
  font-size: 5vw;
  opacity: 0;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

let tl = gsap.timeline({scrollTrigger: {
    trigger: ".text-container",
    start: 0,
    end: "+=1000", // stay pinned for 1000 pixels (make this whatever you want)
    markers: true,
    scrub: true,
    pin: true,
  }});

let stayTime = 1; // seconds between each text flip on the timeline (not literally seconds on screen - we're just spacing them out on the timeline)
let textElements = gsap.utils.toArray(".text"); // get an Array of all the ".text" elements

// loop through each text element and add an autoAlpha flip at the appropriate times on the timeline
textElements.forEach((el, i) => {
  tl.set(el, {autoAlpha: 1}, i * stayTime);
  if (i !== 0) { // if it's the first one, we don't need to toggle the previous one off.
    tl.set(textElements[i - 1], {autoAlpha: 0}, i * stayTime);
  }
});
// add some space at the end of the timeline so the last one stays for the correct duration before things get unpinned.
tl.set({}, {delay: stayTime});

              
            
!
999px

Console