Promo: Nested Timelines
Master Advanced GreenSock Animation Control with Nested Timelines
Key Concepts You'll Master
Timeline Nesting
Learn to organize complex animations by nesting child timelines within a parent timeline for better control and debugging.
Individual Tweens
Discover how to mix individual tweens with nested timelines within the same parent timeline structure.
Error Prevention
Implement strategies to handle connectivity problems and prevent visual glitches during page load.
Exercise Workflow
Modify Existing Functions
Update getStarsTimeline() and getTitlesTimeline() functions to return timeline objects instead of just creating them
Create Parent Timeline
Build a main TimelineLite instance that will contain all nested timelines and individual tweens
Add Connectivity Protection
Implement safeguards against network issues using CSS visibility and autoAlpha properties
This exercise builds on previous work where two separate timelines were playing simultaneously. We'll restructure this code to use a parent timeline architecture for better control.
return tl;
Timeline Execution Behavior
| Feature | Without Position Parameter | With Position Parameter |
|---|---|---|
| Execution Order | Sequential (one after another) | Simultaneous (at same time) |
| Code Example | .add(getTitlesTimeline()) | .add(getTitlesTimeline(), 0) |
| Use Case | Story progression | Layered effects |
GSAP's autoAlpha plugin automatically toggles CSS visibility to hidden when opacity reaches zero, preventing user interaction with invisible elements. This is more robust than using opacity alone.
Animation Sequence Structure
Panel 1: Fade In
Demo div fades in from autoAlpha 0 over 0.5 seconds
Panel 2: Stars Timeline
Starfield animation begins at panel2 label
Panel 2: Titles Timeline
Title animations start simultaneously with stars
Connectivity Protection Strategy
Implementation Steps
Wrap in Function
Contain the main timeline creation within a createTimeline() function to control when it executes
Add CSS Protection
Set visibility:hidden on the demo div in CSS to prevent premature visibility
Use DelayedCall for Testing
Implement TweenLite.delayedCall(1, createTimeline) to simulate network delays
Because all child timelines are contained within a single parent timeline, you can control the entire complex animation sequence with one set of play, pause, and reverse controls.
Production Code Review Points
Ensures timelines can be nested and reused as components
Maintains clean, readable code structure for complex animations
Makes timing adjustments easier and code more maintainable
Demonstrates scalability of the parent timeline approach
Key Takeaways
