GSAP . end
-
Learn how ScrollTrigger
.enddefines where a scroll animation stops and how to control animation length properly.
Introduction
In scroll-based animations, itโs important to know when an animation should stop.
The
.endproperty in GSAP ScrollTrigger defines the point where the scroll-triggered animation ends.Why
.endis important-
Controls animation duration on scroll
-
Helps sync animations with page sections
-
Essential for
scrubandpineffects
-
Basic Concept of
.endThe
.endproperty works together with.start.-
start โ when animation begins
-
end โ when animation finishes
๐ Without
end, GSAP uses a default value.-
Basic Syntax
gsap.to(".box", {
x: 300,
scrollTrigger: {
trigger: ".box",
start: "top 80%",
end: "top 30%"
}
});
What this means
-
Animation starts when
.boxreaches 80% viewport -
Animation ends when
.boxreaches 30% viewport
-
Using Viewport Positions
end: "bottom top"
Value Meaning top Top of trigger element center Center of trigger bottom Bottom of trigger top / center / bottom Viewport positions
Using Scroll Distance
end: "+=300"
End at Another Element
end: ".footer"
- Practical Examples
Scroll-Controlled Animation
gsap.to(".bar", {
width: "100%",
scrollTrigger: {
trigger: ".section",
start: "top center",
end: "bottom center",
scrub: true
}
});
Pin Section Until End
ScrollTrigger.create({
trigger: ".panel",
start: "top top",
end: "+=400",
pin: true
});
Animate Between Two Sections
gsap.fromTo(".image",
{ scale: 0.8 },
{
scale: 1,
scrollTrigger: {
trigger: ".section1",
end: ".section2",
scrub: true
}
}
);