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 class="description panel blue">
    <div>
      <h1>Basic Pin</h1>
      <p>You can <strong>pin</strong> an element while the ScrollTrigger is active which basically make it stick in place while the scroll position is between the <code>start</code> and <code>end</code> elements/values</p>
      <div class="scroll-down">Scroll down<div class="arrow"></div></div>
    </div>
</section>

  <section id="orange" class="panel orange align-top">
      <p id="orange-content"><code>start: "top top"</code> triggers when the orange element's <strong>top edge</strong> hits the <strong>top</strong> of the viewport. <code>end:&nbsp;"bottom&nbsp;150px"</code> stops pinning when the <strong>bottom</strong> of the orange element hits <strong>150px</strong> down from the top of the viewport (measurements are relative to the top).</p>
  </section>

  <section id="red" class="panel red align-top">
    <p id="red-content"><code>start: "top center"</code> pins this element when the <strong>top</strong> of the red element hits the <strong>center</strong> of the viewport, and remains pinned for 200px because its <code>end</code> is defined as <code>"+=200"</code></p>
  </section>
  
  <section class="panel purple">
      Easy Peasy!
  </section>




              
            
!

CSS

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

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

.scroll-down {
  bottom:auto;
  top:6vh;
  position:relative;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

ScrollTrigger.create({
  trigger: "#orange",
  start: "top top", 
  end: "bottom 150px",
  pin: "#orange-content"
});

ScrollTrigger.create({
  trigger: "#red",
  start: "top center", 
  end: "+=200", // 200px past the start 
  pin: "#red-content"
});



// 💚 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/"});
// 💚 Happy tweening!
              
            
!
999px

Console