What is the pin Property in ScrollTrigger?

The pin property in GSAP’s ScrollTrigger plugin allows you to "freeze" an element in place during a scroll-based animation. When an element is pinned, it remains fixed in the viewport while other content continues to scroll past it.

This is particularly useful when you want to:

  1. Highlight specific elements during a scroll.
  2. Create animations tied to scroll progress (e.g., scaling, moving, or rotating elements).
  3. Control the visual flow by "pinning" sections or components for a dynamic storytelling effect.

Task: Increase Image Size on Scroll

Requirements:


Code Implementation:

// Register the ScrollTrigger plugin
gsap.registerPlugin(ScrollTrigger);

// Animate the image width on scroll
gsap.to("#page2 img", {
  width: "100%", // Target width for the animation
  scrollTrigger: {
    trigger: "#page2", // The parent container that gets pinned
    markers: true, // Debug markers to visualize start and end points
    start: "top 0", // Animation starts when #page2 hits the top of the viewport
    end: "top -100%", // Animation ends when the top of #page2 moves 100% above the viewport
    scrub: 2, // Smoothness of the scroll-based animation
    pin: true, // Pins #page2 in place during the animation
  },
});


Explanation of Key Properties:

  1. trigger: