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

              
                <section>
  <div class="bg">
    <img src="" alt="test">
  </div>
  <div class="text-wrapper">
    <h1>Simple parallax sections</h1>
    <p>Just for test</p>
  </div>
</section>
<section>
  <div class="bg">
    <img src="" alt="test">
  </div>
  <div class="text-wrapper">
    <h1>Hey look, a title</h1>
    <p>Just for test</p>
  </div>
</section>
<section>
  <div class="bg">
    <img src="" alt="test">
  </div>
  <div class="text-wrapper">
    <h1>Hey look, a title 2</h1>
    <p>Just for test</p>
  </div>
</section>
<section>
  <div class="bg">
    <img src="" alt="test">
  </div>
  <div class="text-wrapper">
    <h1>Hey look, a title 3</h1>
    <p>Just for test</p>
  </div>
</section>

<header>
   <a href="https://greensock.com/scrolltrigger">
     <img class="greensock-icon" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/scroll-trigger-logo-light.svg" width="200" height="64" />
  </a> 
</header>
              
            
!

CSS

              
                section {
  position: relative;
  border: 1 px solid red;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.text-wrapper {
  color: white;
  border: 1px solid red;
}

p {
  font-size: .75rem;
}

.bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

h1 {
  color: white;
  text-shadow: 1px 1px 3px black;
  z-index: 1;
  font-size: 3em;
  font-weight: 400;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

let getRatio = (el) =>
  window.innerHeight / (window.innerHeight + el.offsetHeight);

gsap.set('.text-wrapper', {opacity: 0})

gsap.utils.toArray("section").forEach((section, i) => {
  const image = section.querySelector(".bg img");
  const textWrapper = section.querySelector('.text-wrapper');

  // Give the backgrounds some random images
  image.src = `https://picsum.photos/1600/800?random=${i}`;
  
  // the first image (i === 0) should be handled differently because it should start at the very top.
  // use function-based values in order to keep things responsive
  gsap.fromTo(
    image,
    {
      backgroundPosition: () =>
        i ? `50% ${-window.innerHeight * getRatio(section)}px` : "50% 0px"
    },
    {
      backgroundPosition: () =>
        `50% ${window.innerHeight * (1 - getRatio(section))}px`,
      ease: "none",
      scrollTrigger: {
        trigger: section,
        start: () => (i ? "top bottom" : "top top"),
        end: "bottom top",
        scrub: true,
        invalidateOnRefresh: true // to make it responsive
      }
    }
  );
  
  
  let animateIn = gsap.timeline({
    scrollTrigger: {
      trigger: textWrapper,
      start: "top 85%",
      end: "bottom 15%",
      markers: "true",
      scrub: true
    }
  });
  animateIn.to(
    textWrapper, {
      opacity: 1,
      ease: "power1.out",
    }, 0
  )
  animateIn.to(
    textWrapper, {
      opacity: 0,
      ease: "power1.out",
    }, '+=3'
  )
});

              
            
!
999px

Console