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 style="height:50vh"></div>
<h1> Some bladiebla </h1>
<p> Filling intro text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.</p>

<p class="animation"> Filling intro text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.</p>

<div style="height:500px"></div>

<p> Filling intro text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.</p>


<div style="height:500px"></div>

<p class="animation"> Filling intro text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque his sapiens semper vacabit. Quid sequatur, quid repugnet, vident. Duo Reges: constructio interrete. Cur haec eadem Democritus? Haec para/doca illi, nos admirabilia dicamus.</p>

<div style="height:50vh"></div>
<section style="height:50vh">
  <h1>Extra space just for demo, remove this</h1>
</section>
              
            
!

CSS

              
                section {
  background-color: grey;
  padding: 2rem;
  margin-bottom: 1rem
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

document.querySelectorAll(".animation").forEach((text) => {
  console.log(text);
  let tl = gsap.timeline();
  tl.set(text, { opacity: 0, y: 150 });

  const animateElement = (yValue, opacityValue) => {
    tl.to(text, {
      opacity: opacityValue, // Start with opacity 0 (fully transparent)
      duration: 1, // Animation duration in seconds
      delay: 0.2,
      y: yValue,
      ease: "power1", // Easing function
      overwrite: true,
    });
  };

  ScrollTrigger.create({
    // ScrollTrigger settings
    trigger: text,
    start: "top 75%", // Start the animation when the top of the element is 75% in view
    end: "bottom 40%",
    markers: true,
    onEnter: () => {
      // Triggered when entering the element
      animateElement(0, 1);
      console.log("onEnter");
    },
    onLeave: () => {
      // Triggered when leaving the element
      animateElement(-150, 0); // Animate to y: -50 and opacity: 0`
      console.log("onLeave");
    },
    onEnterBack: () => {
      // Triggered when entering the element back (scrolling up)
      animateElement(0, 1); // Animate to y: 50 and opacity: 1
      console.log("onEnterBack");
    },
    onLeaveBack: () => {
      // Triggered when leaving the element back (scrolling up)
      animateElement(150, 0); // Animate to y: -50 and opacity: 
      console.log("onLeaveBack");
    }
  });
});

              
            
!
999px

Console