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

              
                <header>
  <ul class="nav">
    <li><a href="#home">Home</a></li>
    <li><a href="#one">Section 01</a></li>
    <li><a href="#two">Section 02</a></li>
    <li><a href="#three">Section 03</a></li>
    <li><a href="#four">Section 04</a></li>
  </ul>
</header>


<div id="home" class="description panel blue">
  <div><h1>Layered pinning</h1>
    <p>Use pinning to layer panels on top of each other as you scroll.</p>
    <div class="scroll-down">Scroll down<div class="arrow"></div></div>
  </div>
</div>


<section id="one" class="panel red">
	ONE
</section>
<section id="two" class="panel orange" style="height: 220vh">
	TWO
</section>
<section id="three" class="panel purple" style="height: 50vh">
	THREE
</section>
<section id="four" class="panel green">
	FOUR
</section>
              
            
!

CSS

              
                header {
  position:fixed;
  width: 100%;
}
ul.nav {
  list-style-type:none;
  display: inline-flex;
}
ul.nav li a {
  color:#fff;
  text-decoration:none;
}
ul.nav li:nth-child(n+2) a {
  padding-left: 50px;
}

ul.nav li a.active {
  color: yellow;
}

.panel {
  border-radius:30px;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);

let panels = gsap.utils.toArray(".panel");

panels.forEach((panel, i) => {
  ScrollTrigger.create({
    trigger: panel,
    start: () => panel.offsetHeight < window.innerHeight ? "top top" : "bottom bottom",
    pin: true,
    pinSpacing: false,
    end: () => "+=" + panel.offsetHeight,
    pinType: "fixed"
  });
});

ScrollTrigger.create({
  snap: {
    snapTo: "labels",
    duration: 0.5
  }
});

let menu = gsap.utils.toArray(".nav a");
menu.forEach(a => {
let element = document.querySelector(a.getAttribute("href")),
      linkST = ScrollTrigger.create({
            trigger: element,
            start: "top top"
          });
  ScrollTrigger.create({
    trigger: element,
    start: "top center",
    end: "bottom center",
    onToggle: self => self.isActive && setActive(a)
  });
  a.addEventListener("click", (e) => {
  e.preventDefault();
  const target = e.target.getAttribute("href") === "#home" ? 0 : linkST.start;
  gsap.to(window, {
    duration: 1,
    scrollTo: target,
    overwrite: "auto",
  });
});
});

function setActive(links) {
  menu.forEach(el => el.classList.remove("active"));
  links.classList.add("active");
}

              
            
!
999px

Console