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>
  <nav>
    <a href="#sections1" role="link">box1</a>
    <a href="#sections2" role="link">box2</a>
    <a href="#sections3" role="link">box3</a>
    <a href="#sections4" role="link">box4</a>
  </nav>
</header>

<section id="sections1">
  <h1>
    Test
  </h1>
</section>
<section id="sections2">
  <h1>
    Test
  </h1>
</section>
<section id="sections3">
  <h1>
    Test
  </h1>
</section>
<section id="sections4">
  <h1>
    Test
  </h1>
</section>
              
            
!

CSS

              
                section {
  height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-block: 100vh;
  border: 2px solid pink;
}

h1 {
  font-family: cursive;
  font-size: 4rem;
  width: fit-content;
  border: 2px solid red;
  padding: 2rem;
  border-radius: 2rem;
}

nav {
  display: flex;
  gap: 5rem;
  justify-content: center;
  padding: 1rem;
  background-color: rgb(42, 36, 36);
  font-family: cursive;
  font-size: 1.3rem;
}

nav a {
  text-decoration: none;
  color: pink;
  text-transform: capitalize;
}

              
            
!

JS

              
                // initialize lenis smooth scrolling
const lenis = new Lenis({
  lerp: 0.07, // animation smoothness (between 0 & 1)
  wheelMultiplier: 0.7, // scrolling speed for mouse wheel
  touchMultiplier: 0.7, // scrolling speed for touch events
  smoothWheel: true, // smooth scrolling for while events
  smoothTouch: true, // smooth scrolling for touche events
  orientation: "vertical", // orientation of the scrolling (vertical/horizontal)
  gestureOrientation: "vertical", // orientation of the gestures (vertical/horizontal)
  normalizeWheel: false, // Normalize wheel inputs
  infinite: false, // infinite scroll
  autoResize: true
});

function raf(time) {
  lenis.raf(time);
  requestAnimationFrame(raf);
}
requestAnimationFrame(raf);

// Function to stop all GSAP animations
function pauseAnimations() {
  // disable ScrollTrigger animations
  ScrollTrigger.getAll().forEach((trigger) => {
    trigger.disable();
  });
}

// Function to resume all GSAP animations
function resumeAnimations() {
  // enable ScrollTrigger animations
  ScrollTrigger.getAll().forEach((trigger) => {
    trigger.enable();
  });
}

// smoothe scrolling in anchor links
document.querySelectorAll("nav a").forEach((link) => {
  link.addEventListener("click", (e) => {
    e.preventDefault();
    // Pause the GSAP animations
    pauseAnimations();
    lenis.scrollTo(`${e.target.getAttribute("href")}`, {
      lerp: 0.09,
      onComplete: () => {
        // Resume GSAP animations after scrolling is complete
        resumeAnimations();
      }
    });

    // const targetSection = document.querySelector(`${e.target.getAttribute("href")}`);
    // targetSection.scrollIntoView({ behavior: "smooth" });
  });
});

// Select all h1 elements within section elements
const h1Elements = document.querySelectorAll("section h1");

// Loop through each h1 element and apply the GSAP animation
h1Elements.forEach((h1) => {
  gsap.from(h1, {
    scrollTrigger: {
      trigger: h1.parentElement, // Use the parent section as the trigger
      toggleActions: "play pause resume reset",
      start: "top top",
      end: "bottom center+=20px",
      // satrt/end : start/end scroller-start/end
      // start/end : trigger viewport
      scrub: 1,
      pin: true,
      markers: true // For debugging
    },
    x: 600,
    rotation: 180,
    duration: 3,
    ease: "linear",
    color: "red"
  });
});

              
            
!
999px

Console