Tween Control: Free GreenSock Tutorial
Master GreenSock Animation Control with Professional Tweening
Core GreenSock Concepts You'll Master
Element Positioning
Learn to use Set() method for instant positioning changes without animation duration. Perfect for setting initial states.
Transform Origins
Control the exact point around which rotations and transforms occur. Rotate from corners, edges, or custom positions.
Tween Control
Master play(), reverse(), and pause() methods to create interactive animations that respond to user input dynamically.
Animation Development Workflow
Preview Target Animation
Open finished.html in Chrome to understand the final interactive speed gauge animation behavior
Analyze DOM Structure
Examine the HTML structure with speedGauge div containing pointer and center images
Position Elements
Use Set() method to move pointer to correct starting position before animation begins
Configure Transforms
Set transformOrigin property to control rotation point and direction specifiers for clockwise motion
Add Interactivity
Implement mouseenter and mouseleave events to control tween playback and reversal
The animation relies on a simple structure: a speedGauge container div with two images - the pointer we'll animate and a center disc. The gauge background is applied via CSS to the container div.
Set() vs Traditional CSS Approach
| Feature | GreenSock Set() | Traditional CSS |
|---|---|---|
| Code Lines | Single line | Multiple lines |
| Vendor Prefixes | Automatic | Manual required |
| Animation Duration | Instant (0) | Must specify |
| Cross-browser | Built-in support | Manual testing |
Ensure your code matches this exact syntax before proceeding:
TweenLite.set($pointer, {rotation:90, transformOrigin:"0px 4px"});Now let's position the pointer at its correct starting position. Change the rotation value to 142 degrees:
TweenLite.set($pointer, {rotation:142, transformOrigin:"0px 4px"});
This specific angle aligns the pointer with the leftmost notch of our speedometer, creating the proper "idle" state before animation begins.
Save and preview the page. Perfect! The pointer now assumes its correct starting position at the bottom-left of the gauge, ready for our interactive animation sequence.
Transform Origin Options
Keywords
Use descriptive terms like 'left', 'right', 'center', 'top', 'bottom' for intuitive positioning. Example: 'right bottom'.
Percentages
Relative positioning where '100% 100%' equals bottom-right corner. Scales with element size changes automatically.
Pixel Values
Exact positioning for precise control. '100px' means 100 pixels from both top and left edges of the element.
Mixed Approaches
Combine different units like '50% bottom' for horizontal percentage positioning with vertical keyword alignment.
Save and preview the page. Excellent! The animation now moves in the correct clockwise direction, creating the expected speedometer acceleration effect.
Understanding rotation values is crucial for complex animations. Even though we used set() to establish a 142° starting position, GSAP treats the target rotation of 20° as relative to the element's original 0° state, not the modified position. This behavior allows for consistent animation logic regardless of initial transformations.

Rotation Direction Control
Assigning tweens to variables is essential for interactive animations. Without a reference, you cannot pause, play, reverse, or otherwise control the tween after creation.
Pausing Methods Comparison
Interactive Animation Implementation
Create Paused Tween
Initialize tween with paused:true property to prevent automatic playback on page load
Add Mouse Enter Handler
Use jQuery mouseenter() event to trigger pointerTween.play() when user hovers over gauge
Add Mouse Leave Handler
Implement mouseleave() event with pointerTween.reverse() to smoothly reverse animation from current position
GreenSock's reverse() method maintains timing and easing properties when reversing from any point in the animation, creating fluid user interactions without jarring transitions.
Key Takeaways




