Back to home
gsap

Scroll Trigger

This demo shows how to animate elements when they enter the viewport using GSAP’s ScrollTrigger plugin. It uses a scrollable container instead of the full page scroll, and includes dynamic control of the toggleActions and markers for learning purposes.

How it works

  • The ScrollTrigger plugin watches each .box inside a scrollable container.
  • When a box enters the viewport (start: "top bottom"), an animation plays that moves it in from the left with a fade (x: "-300%", opacity: 0).
  • Each box has its own ScrollTrigger instance.
  • The scroller is explicitly set to a custom container (#scroll-area), so it doesn’t use the default window scroll.

Key ScrollTrigger Options

OptionDescription
triggerThe element that triggers the animation.
scrollerThe scrollable container. If omitted, window is used.
toggleActionsA string that defines what happens on scroll events. Format: "onEnter onLeave onEnterBack onLeaveBack"
markersWhen true, displays markers to debug where triggers start/end.
startDefines when the animation starts. Example: "top bottom" means the top of the element hits the bottom of the scroller.

Common toggleActions combos

ComboBehavior
play none none nonePlays on enter, does nothing on other events.
restart none none noneAlways restarts when entering.
play pause resume resetControls full lifecycle of scroll.
play reverse play reversePlays on enter, reverses on leave.