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

              
                
  <div class="description panel blue">
    <div><h1>Callbacks</h1>
      <ul>
        <li><code>onEnter</code> - forward past "start" (typically when <code>trigger</code> is scrolled into view)</li>
        <li><code>onLeave</code> - forward past "end" (typically when <code>trigger</code> is scrolled out of view)</li>
        <li><code>onEnterBack</code> - backward past "end" (typically when <code>trigger</code> is scrolled back into view)</li>
        <li><code>onLeaveBack</code> - backward past "start" (typically when <code>trigger</code> goes backward out of view)</li>
        <li><code>onUpdate</code> - every time the scroll position changes while between "start" and "end".</li>
        <li><code>onToggle</code> - passes the start or end in either direction</li>
        <li><code>onRefreshInit</code> - immediately before measurements are recalculated (typically on resize)</li>
        <li><code>onRefresh</code> - after measurements are recalculated (typically on resize)</li>
      </ul>
      <div class="scroll-down">Scroll down<div class="arrow"></div></div>
    </div>
  </div>


  <section class="panel red">
    <p><span class="line line-1"></span>When this panel's top edge reaches 100px from the top of the viewport, the ScrollTrigger will start (<code>start: "top 100px"</code>), then end when its bottom is 100px from the bottom of the viewport (<code>end: "bottom bottom-=100px"</code>). Callbacks are logged to the right, and progress below: <br><span class="red-progress">progress: 0</span></p>
    <div class="log red-log"></div>
  </section>




<section class="panel gray">
  <p>All callbacks receive one parameter - the <strong>ScrollTrigger&nbsp;instance</strong> itself which has properties like <code>progress</code>, <code>direction</code>, and <code>isActive</code>.</p>
</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

              
                /*
	Demo Styles: NOT REQUIRED
*/
.line {
  width: 100%;
  max-width: 800px;
  height: 8px;
  margin: 0 0 10px 0;
  position: relative;
  display: inline-block;
  background-color: rgba(255,255,255,1);
}

.red {
  flex-direction: row;
}
.orange, .purple {
  margin-bottom: 100vh;
}

.log {
  width: 150px;
  height: 150px;
  background-color: black;
  padding: 8px;
  border-radius: 8px;
  text-align: left;
  font-size: 15px;
  font-family: monospace, courier;
  color: #ccc;
  font-weight: 300;
  max-height: 90%;
  overflow-y: scroll;
  margin-left: 10px;
}

.red .red-progress {
  color: white;
  font-weight: 400;
  font-size: 1.3em;
  padding-top: 14px;
  display: inline-block;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

const redLog = document.querySelector(".red-log"),
      redProgress = document.querySelector(".red-progress");

function logRed(text) {
  redLog.innerHTML += text + "<br>";
}

var animation = gsap.from(".line-1", {
  scaleX: 0,
  transformOrigin: "left center", 
  ease: "none"
});

ScrollTrigger.create({
  trigger: ".red",
  start: "top 100px",
  end: "bottom bottom-=100px",
  markers: {startColor: "white", endColor: "white"},
  scrub: true,
  animation: animation,
  onEnter: () => logRed("onEnter"),
  onLeave: () => logRed("onLeave"),
  onEnterBack: () => logRed("onEnterBack"),
  onLeaveBack: () => logRed("onLeaveBack"),
  onRefresh: () => logRed("onRefresh"),
  onUpdate: self => redProgress.innerText = "progress: " + self.progress.toFixed(3)
});
  

  


              
            
!
999px

Console