Skip to main content
GSAP Animation TutorialArticle 18

GSAP ScrollTrigger toggleActions: Control Play, Pause, Resume, Reverse & Restart

Turn four scroll-boundary events into clear animation commands, decode action strings, and build reliable replay and reverse behavior.

GSAP ScrollTrigger toggleActions Play Pause Resume Reverse Tutorial - NavTechSolution

scrub makes scroll progress the playhead. pin holds content in place. toggleActions is different: it runs commands when the scroll position crosses a trigger's start or end boundary.

This lesson builds on GSAP easing, timeline sequencing, timeline controls, the position parameter, timeline stagger, ScrollTrigger fundamentals, start and end positions, and scroll-linked scrub. The planned pin article is not linked because its PHP page is not present in this backup.

gsap.from(".feature", {
  y: 50,
  opacity: 0,
  scrollTrigger: {
    trigger: ".feature",
    start: "top 80%",
    end: "bottom 20%",
    toggleActions: "play pause resume reverse"
  }
});

1. What is toggleActions?

It is a four-command string. Each command belongs to one boundary event, and order is the entire mental model.

SCROLL DOWNonEnterSTARTACTIVE RANGEENDonLeave
SCROLL UPonEnterBackENDACTIVE RANGESTARTonLeaveBack
Direction changes which event fires at the same physical boundary.

2. The four positions

toggleActions: "play pause resume reverse"
1onEnterplay
2onLeavepause
3onEnterBackresume
4onLeaveBackreverse
onEnter

Cross START while scrolling down

onLeave

Cross END while scrolling down

onEnterBack

Cross END while scrolling up

onLeaveBack

Cross START while scrolling up

3. Read an action string from left to right

"play pause resume reverse" means play on entry, pause after the end, resume when returning through the end, then reverse after moving back above the start.

4. Available actions

play

Continue forward from the current position

pause

Stop at the current position

resume

Continue after a pause

reverse

Animate backward from the current position

restart

Return to zero and play

reset

Return to zero and pause

complete

Jump to the completed state

none

Take no action

5. Useful beginner patterns

play none none nonePlay once on first entry
play none none reversePlay entering, reverse above start
play pause resume reverseControl every boundary
restart none none noneReplay from zero on every entry
play none none resetPlay entering, jump back above start

6. Interactive Action Decoder

toggleActions: "play pause resume reverse"

7. Live boundary demo

Scroll through the stage in both directions. The current event is announced without making the content depend on motion.

START
SCROLL ACTION
END

Waiting for a boundary...

8. toggleActions versus scrub

TOGGLE ACTIONSBoundary crossedRun a command
SCRUBScroll progressAnimation progress

Scrub continuously owns progress. Combining it with toggle actions is possible but often confusing because both features try to influence the same playhead.

9. toggleActions versus pin

toggleActionscontrols behavior
pincontrols position
scrubcontrols progress

10. Timeline control

Attach one ScrollTrigger to a timeline to control the whole sequence as a unit.

const tl = gsap.timeline({
  scrollTrigger: {
    trigger: ".service-story",
    start: "top 75%",
    end: "bottom 25%",
    toggleActions: "play none none reverse"
  }
});

tl.from(".label", { y: 15, opacity: 0 })
  .from(".title", { y: 35, opacity: 0 })
  .from(".cards", { y: 30, opacity: 0, stagger: 0.1 });
LABELTITLETEXTCARDSone timeline / four boundary commands

11. Practical section examples

NavTechSolution

Services built to move ideas forward

Use one scoped timeline for the heading and cards.

Web Development
AI Solutions
SEO
UI/UX
ABOUT

Reveal a label, heading and supporting paragraph once.

PORTFOLIO

Reverse cards naturally when scrolling back above the section.

12. Similar actions, important differences

REVERSEAnimates backwardRESETJumps to start and pauses
RESUMEContinues from pauseRESTARTReturns to zero and plays
PLAYContinues from current positionRESTARTAlways begins again

13. Event logger

Cross my boundaries
  1. Logger ready

14. Main toggleActions Lab

NavTechSolution Lab

Control Scroll Events

Choose four actions, rebuild only this lab, then cross its boundaries.

GSAP
Enter
Play
Leave Back
Reverse
toggleActions: "play none none reverse"

Lab ready.

15. Start, end and scroll direction still matter

SCROLL DOWNonEnter ↓STARTACTIVE RANGEENDonLeave ↓
SCROLL UPonEnterBack ↑ENDACTIVE RANGESTARTonLeaveBack ↑

16. Common mistakes

  • Providing fewer than four action positions.
  • Mixing up onLeave and onLeaveBack.
  • Using an unsupported action name.
  • Expecting toggleActions to behave like scrub or pin.
  • Using reset where a visible jump causes flashing.
  • Rebuilding a demo without killing only its old trigger.
  • Leaving markers enabled in production.
  • Hiding essential content before JavaScript runs.

17. Debugging checklist

1GSAP loaded
2ScrollTrigger loaded
3Plugin registered
4Trigger exists
5Start is reachable
6End is reachable
7Exactly four valid actions
8Correct scroll direction
9No accidental duplicate trigger
10Temporary markers checked

18. Performance, accessibility and mobile

Prefer transforms and opacity, keep entrances short, avoid a trigger for every small word, and test quick direction changes on touch devices. Content remains visible when JavaScript fails.

Reduced motion

This tutorial detects prefers-reduced-motion, skips repeated scroll-controlled animation, and leaves every heading, card and control readable.

19. Mini challenge

NavTechSolution

Control Scroll Events

Play this animation when entering and reverse it when scrolling back above.

Enter
Play
Leave Back
Reverse

20. Quick reference

ActionBehavior
playContinue forward from the current position
pauseStop at the current position
resumeContinue after a pause
reverseAnimate backward from the current position
restartReturn to zero and play
resetReturn to zero and pause
completeJump to the completed state
noneTake no action
PositionEvent
1onEnter
2onLeave
3onEnterBack
4onLeaveBack

21. Cheat sheet

toggleActions: "play pause resume reverse"
1onEnterPLAY
2onLeavePAUSE
3onEnterBackRESUME
4onLeaveBackREVERSE

22. Final mental model

toggleActions: "A B C D"
AonEnter
BonLeave
ConEnterBack
DonLeaveBack
Always map the four commands to the four events before debugging the animation itself.

23. Three original post designs

These alternate NavTechSolution visuals reinforce the same four-event model without relying on external screenshots.

GSAP toggleActions four event control panel design
Four-event action console
GSAP toggleActions syntax and boundary map design
Syntax and boundary map

24. Coming next

Planned Blog #19

GSAP ScrollTrigger + Timeline

Build advanced scroll animation sequences by combining timelines, stagger, start/end boundaries and intentional action patterns.

Frequently asked questions

What is toggleActions in GSAP ScrollTrigger?

toggleActions assigns animation commands to the four moments when a trigger crosses its start and end boundaries.

What are the four toggleActions positions?

In order they are onEnter, onLeave, onEnterBack and onLeaveBack.

What does onEnter mean?

It fires when scrolling forward crosses the start boundary and enters the active range.

What does onLeave mean?

It fires when scrolling forward crosses the end boundary and leaves the active range.

What does onEnterBack mean?

It fires while scrolling backward across the end boundary into the active range.

What does onLeaveBack mean?

It fires while scrolling backward across the start boundary and leaves the active range.

What is the difference between play and restart?

play continues from the current playhead position; restart returns to the beginning and plays.

What is the difference between resume and restart?

resume continues from a paused position; restart begins again from time zero.

What is the difference between reverse and reset?

reverse animates backward; reset jumps to the beginning and pauses.

What does none do?

It deliberately performs no command for that boundary event.

Can I use toggleActions with a GSAP timeline?

Yes. Place ScrollTrigger on the timeline and the selected actions control the entire sequence.

What is the difference between toggleActions and scrub?

toggleActions runs commands at boundary crossings; scrub continuously maps scroll progress to animation progress.

Can I combine toggleActions and pin?

Yes, although each option solves a different problem and should be added only when the experience needs it.

Why is my ScrollTrigger animation not replaying?

The default actions may play only on first entry. Use restart or a reverse/reset action at the appropriate boundary.

Can I use toggleActions on a PHP website?

Yes. PHP renders HTML while GSAP and ScrollTrigger run in the browser.