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="description panel orange">
    <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>

              
            
!

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;
}

.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;
}

.panel {
	width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  font-size: 1.5em;
  text-align: center;
  color: white;
  position: relative;
  box-sizing: border-box;
  padding: 10px;
}

.panel.align-top {
  align-items: flex-start;
}

.panel h1 {
  font-size: 1.8em;
  color: white;
  font-weight: 300;
  margin: 0 auto;
}
.panel.description {
  padding-bottom: 60px;
}
.panel p, .panel li {
  color: black;
  font-weight: 400;
  text-align: left;
  font-size: 0.8em;
  line-height: 1.5em;
  margin: 0.3em 0 1em 0;
}
.panel li {
  margin: 0;
}

h1, h2, p, li {
  max-width: 800px;
}
              
            
!

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: "#111", endColor: "#111"},
  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)
});
  

// 💚 This just adds the GSAP link to this pen, don't copy this bit
import { GSAPInfoBar } from "https://codepen.io/GreenSock/pen/vYqpyLg.js"
new GSAPInfoBar({ link: "https://gsap.com/docs/v3/Plugins/ScrollTrigger/", position:'top'});
// 💚 Happy tweening!
              
            
!
999px

Console