TweenMax: Free GreenSock Tutorial
Master Advanced Animation with TweenMax Library Features
TweenMax Core Features
Animation Repetition
Control how many times animations repeat with flexible options including infinite loops and yoyo effects for back-and-forth motion.
Advanced Callbacks
Utilize onStart, onRepeat, and onComplete callbacks to trigger functions at specific animation phases for dynamic content updates.
Timing Control
Implement delays and repeat delays to create sophisticated timing patterns between animation sequences.
TweenLite vs TweenMax
| Feature | TweenLite | TweenMax |
|---|---|---|
| File Size | Lightweight Core | ~30kb Minified |
| Repeat Features | Not Available | Full Support |
| Bundled Plugins | Minimal | 9+ Plugins Included |
| Callback Options | Basic | Advanced |
Setting Up the Animation Structure
Define Variables
Create jQuery objects for car and message elements, initialize count tracker, and prepare tween variable for animation assignment
Inspect DOM Elements
Examine the demo div containing message and car elements, noting the background image sprite technique for multiple car visuals
Preview Initial State
View the starting layout with cars displayed as a vertical strip before applying overflow hidden and animation effects
Create your foundational tween around line 63:
$(document).ready(function() {
var $car = $("#car"),
$message = $("#message"),
count = 0,
tween;
tween = TweenMax.to($car, 1, {x:1250});
});Save and preview the file. The cars immediately animate across the screen over 1 second, reaching an x-position of 1250 pixels. While functional, this immediate start lacks the polished feel of professional animations.
Add a strategic delay to improve the user experience:
tween = TweenMax.to($car, 1, {x:1250, delay:1});Test the delay in your browser. The 1-second pause creates anticipation and allows users to register the initial state before animation begins.
The default Power1.easeOut creates natural-feeling motion, but our car animation requires mechanical consistency. Linear motion better represents vehicle movement at steady speeds.
Implement linear easing for realistic vehicle motion:
tween = TweenMax.to($car, 1, {x:1250, ease:Linear.easeNone, delay:1});
Linear.easeNone provides constant velocity throughout the animation—perfect for simulating steady vehicle movement without acceleration or deceleration curves.
Preview the linear motion in your browser. The cars now move with consistent, mechanical precision.
Now let's explore TweenMax's signature repeat functionality:
tween = TweenMax.to($car, 1, {x:1250, ease:Linear.easeNone, delay:1, repeat:-1});
Setting repeat:-1 creates infinite looping—powerful for continuous animations, loading indicators, or ambient motion effects.
Test the infinite repeat. While impressive initially, infinite loops can overwhelm users, so use them judiciously in production work.
Experiment with TweenMax's yoyo feature, which creates pendulum-like motion:
tween = TweenMax.to($car, 1, {x:1250, ease:Linear.easeNone, delay:1, repeat:-1, yoyo:true});Observe the back-and-forth motion in your browser. The yoyo effect works beautifully for UI elements that need to draw attention or simulate physical pendulum behavior.
Let's create a more practical animation sequence. Remove the yoyo property and implement controlled repetition:
tween = TweenMax.to($car, 1, {x:1250, ease:Linear.easeNone, delay:1, repeat:4, repeatDelay:0.5});
repeatDelay adds breathing room between animation cycles, creating a more natural rhythm and preventing the jarring immediacy of continuous loops.
Test the refined animation. The 0.5-second delays create a professional cadence—the animation runs five total times (initial play plus four repeats) with comfortable pauses between each cycle.
Animation Callback Sequence
onStart Triggered
startHandler makes GO message visible when animation begins
onRepeat Executes
repeatHandler updates counter, changes message text, and shifts background position
onComplete Fires
completeHandler displays final 'The End' message when all repeats finish
Using backgroundPosition with relative values (-=160px) creates the illusion of different cars by shifting the sprite image vertically with each repeat cycle.
Final Implementation Steps
Prevents multiple cars from being visible simultaneously
Ensures GO message only appears when animation starts
Creates smooth car transitions using sprite sheet technique
Verify onStart, onRepeat, and onComplete work correctly
Key Takeaways


