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:
pin property will ensure that the image's parent section (#page2) remains fixed in place during the animation.// 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
},
});
trigger:
#page2 is used as the trigger instead of directly targeting the image. This ensures the animation behaves predictably and is easier to manage.