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

              
                <body>
  <div class="space">
    This is some white space to show the animation.
  </div>
  <div id="about-us">
    <div>About Us</div>
    <div>Content</div>
    <div>Content 2</div>
  </div>
  <div class="space">
    This is some white space to show the animation.
  </div>
</body>
              
            
!

CSS

              
                .space {
  height: 110vh;
}
#about-us {
  display: flex;
  flex-flow: column nowrap;
  height: 100vh;
}
#about-us div {
  height: 25vh;
}
#about-us div:nth-child(1) {
  background: red;
}
#about-us div:nth-child(2) {
  background: green;
}
#about-us div:nth-child(3) {
  background: blue;
}
              
            
!

JS

              
                console.clear(); // Start with a clean console on refesh
animateAboutUs();

ScrollTrigger.defaults({
  markers: true
});
function animateAboutUs() {
  var elements = gsap.utils.toArray("#about-us > div");
  console.log(elements);
  fadeInDownOutUp(elements, "#about-us", "top 400", "bottom 300");
}

function fadeInDownOutUp(elements, trigger, start, end) {
  let animation = gsap.timeline({
    // yoyo: true, This doenst do anything in this case, yoyo needs aleast one repeat to function
    // autoAlpha: 1, // I'm not aware that you could set this
    scrollTrigger: {
      trigger: trigger,
      start: start,
      end: end,
      scrub: 1,
      markers: true,
      onEnter: function (elements, trigger) { // onEnter is a callback for the scrolltrigger not for tweens
        console.log("enter", elements, trigger);
      }
    }
  });
  // }, 0); This is a postion paramenter for tweens, I dont know what this would do on a timeline

  // fade in the elements from bottom, then fade out again to top
  animation.from(elements, {
    duration: 0.8,
    opacity: 0,
    y: 150,
    stagger: 0.1,
    // immediateRender: false,
    ease: "power2.inOut",
    onStart: function (elements, trigger) {
      // onEnter is a ScrollTrigger callback not a tween call back onStart is for tweens.
      console.log("Tween enter", elements, trigger);
    }
  });
  animation.to(elements, {
    duration: 1,
    opacity: 1,
    y: 0,
    stagger: 0.1,
    // immediateRender: false,
    ease: "power2.inOut"
  });
  animation.to(elements, {
    duration: 0.8,
    opacity: 0,
    y: -150,
    stagger: 0.1,
    // immediateRender: false,
    ease: "power2.inOut"
  });
}

              
            
!
999px

Console