ScrollTrigger start, trigger and vars
-
Learn how
trigger,start, andvarsdefine when and how GSAP ScrollTrigger animations begin.
Introduction
Every ScrollTrigger animation answers three important questions:
-
Which element should be watched? →
trigger -
When should animation start? →
start -
Where are all settings stored? →
vars
Understanding these three makes ScrollTrigger easy and predictable.
-
What is trigger?
trigger defines which element controls the scroll behavior.
scrollTrigger: {
trigger: ".section"
}
The animation reacts when
.sectionscrolls into view.Common Use
-
Section animations
-
Card reveals
-
Text animation
-
The animation reacts when .section scrolls into view. Common Use Section animations Card reveals Text animation
element-position viewport-position
start: "top 80%"
Meaning
-
top→ top of trigger element -
80%→ 80% down the viewport
-
Common
startValuesValue Meaning top bottomElement enters viewport top centerElement reaches center top topElement hits top of screen center centerPerfect alignment +=100After 100px scroll
What are
vars?varssimply means all configuration options passed to ScrollTrigger.📌 In GSAP,
vars= the object insidescrollTrigger.
Basic Syntax (Trigger + Start + Vars)
gsap.to(".box", {
x: 200,
duration: 1,
scrollTrigger: {
trigger: ".box",
start: "top 75%",
markers: true
}
});
Breakdown
-
trigger→.box -
start→ when animation begins -
vars→ all ScrollTrigger settings
-
Fade In Section on Scroll
gsap.from(".section", {
opacity: 0,
y: 50,
scrollTrigger: {
trigger: ".section",
start: "top 80%"
}
});
Start Animation Later
gsap.to(".image", {
scale: 1.2,
scrollTrigger: {
trigger: ".image",
start: "center center"
}
});
: Using vars with Multiple Options
ScrollTrigger.create({
trigger: ".panel",
start: "top top",
end: "+=300",
pin: true,
markers: true
});