Greensock is a fantastic JavaScript animation framework that performs above and beyond everything else currently available to those of us working with web design.
Though only few people know of it in the JavaScript world it’s got a huge audience in the world Flash, where it’s about as widely used as jQuery is among JavaScript-folks.
The example ’3D-flip image gallery’ has been updated to use the newly added 3D features of Greensock. I’ve also added a couple of new example links.
Differences between jQuery and Greensock
You might be thinking “I already have jQuery! I don’t need another JavaScript animation library.” … While you might feel like jQuery’s animation tools are enough, that’s roughly compared to feeling your old mobile phone is sufficient until you try a smart phone and discover the world of possibilities it gives you to walk around with the internet in your pocket.
A few of the things Greensock does that jQuery doesn’t
- It performs extremely well. About 10 times faster than jQuery. Check out this speed test.
- It makes it very easy to animate groups of items either by appending one animation after another or by applying staggered delay/start time for a sort of dominos effect.
- It makes animating transforms like scale, skew and rotate easy. At the same time it handles all the cross-browser junk enabling transforms all the way back to IE6.
- You can animate any numeric value of any object, not just CSS properties. This means that Greensock can animate custom JavaScript objects or work in conjunction with HTML5 Canvas or Raphael.js (For animated vector graphics). It’s extremely flexible in that sense.
- Great easing modes built right in. You don’t need to include any other files, just load up TweenMax.min.js and you have everything you need.
On top of that I’d argue that Greensock has a much better syntax. You can even choose wether or not you want it to be Object Oriented.
Examples
Here are a couple of examples demonstrating the core features of the Greensock Animation Platform. If you have any questions, please leave those in the comments below.
basic syntax

<section id="canvas">
<div id="box"></div>
</section>
var $box = $('#box');
function moveBox(e) {
var x = e.pageX,
y = e.pageY;
TweenMax.to($box, 1.4, {
css: { left: x, top: y, scale: Math.random() * 2 + 1 },
ease:Elastic.easeOut
});
}
$(window).on('click', moveBox);
View demo Mouse follower

In this example TweenMax is used to create a mouse-follow effect in 6 lines of code. It also shows you how awesome it is at overwriting tweens.
This is exactly the same code as above, except we use listen for the mousemove event rather than a click.
<section id="canvas">
<div id="box"></div>
</section>
var $box = $('#box');
function moveBox(e) {
TweenLite.to($box, 0.7, { css: { left: e.pageX, top: e.pageY }});
}
$(window).on('mousemove', moveBox);
View demo 3D-flip image gallery

This example uses some of the newly added 3D features. They aren’t supported in old versions of Internet Explorer, but otherwise they work just great.
<section id="canvas">
<ul>
<li><img src="img/1.jpg" alt="" width="384" height="240" /></li>
<li><img src="img/2.jpg" alt="" width="384" height="240" /></li>
<li><img src="img/3.jpg" alt="" width="384" height="240" /></li>
<li><img src="img/4.jpg" alt="" width="384" height="240" /></li>
<li><img src="img/5.jpg" alt="" width="384" height="240" /></li>
</ul>
</section>
CSSPlugin.defaultTransformPerspective = 500;
var $imgWrap = $('.images'),
$images = $imgWrap.find('img'),
$currImg = $images.eq(0),
index = 0,
numImgs = $images.length,
isAnimating = false;
// Animation properties
var flipDepth = -500,
flipDur = 1;
var flip = function(e) {
// Ignore click until any current animations have completed.
if (isAnimating) return;
isAnimating = true;
// Add +1 to index or loop back to 0 if we've reached the end
index = (index++ >= numImgs - 1) ? 0 : index;
// Get a random value between -25 and 25
var randomVal = Math.random() * 50 - 25;
var tl = new TimelineLite({
onComplete: function() {
$currImg = $images.eq(index);
isAnimating = false;
}
});
tl.to($currImg, flipDur / 2, {
css: {rotationY: 90, z: flipDepth, rotationX: randomVal, alpha: 0.3},
ease:Expo.easeIn
});
tl.append(function() {
$currImg.hide();
$images.eq(index).show();
})
tl.fromTo($images.eq(index), flipDur / 2,
// We need to flip the number sign for rotationX, so we do -randomVal instead of randomVal
{css: {rotationY: -90, z: flipDepth, rotationX: -randomVal, alpha: 0.3}},
{css: {rotationY: 0, z: 0, rotationX: 0, alpha: 1}, ease:Expo.easeOut}
);
};
// Animate first image in
TweenMax.fromTo($currImg, 1.8,
{css: {rotationY: -110, rotationX: Math.random() * 35, z: -1000, alpha: 0}},
{css: {rotationY: 0, rotationX: 0, z: 0, alpha: 1}, ease: Power3.easeInOut, onComplete: function() {
$imgWrap.on('click', flip);
}});
$currImg.show();
View demo Animating custom properties

Here I’m animating the custom property ‘currVal’ of a normal JavaScript object which then updates the number . Notice how easing still works.
<form id="number-input" action="">
<input type="number" value="2500" />
<button id="animate">Animate</button>
</form>
var $text = $('p.number'),
$input = $('input[type=number]'),
endVal = 0,
currVal = 0,
obj = {};
obj.getTextVal = function() {
return parseInt(currVal, 10);
};
obj.setTextVal = function(val) {
currVal = parseInt(val, 10);
$text.text(currVal);
};
obj.setTextVal(0);
var animate = function(e) {
e.preventDefault();
currVal = 0; // Reset this every time
endVal = $input.val();
TweenLite.to(obj, 7, {setTextVal: endVal, ease: Power2.easeInOut});
};
$('#number-input').on('submit', animate);
View demo Controlling the animation playhead

Here I’m using the mouse position to control the progress (or playhead) of the entire animation.
<section id="canvas">
<span>W</span>
<span>o</span>
<span>o</span>
<span>o</span>
<span>o</span>
<span>t</span>
<span>!</span>
<span>!</span>
</section>
var $letters = $('.text span'),
tl = new TimelineMax({paused: true});
tl.staggerFrom($letters, 1.5, {
css: {alpha: 0, top: "-300", scale: 0, rotation: -20},
ease: Elastic.easeOut
}, 0.2);
$(window).on('mousemove', function(e) {
var prog = e.pageX / window.innerWidth;
tl.progress(prog);
});
View demo More examples
- The animation on my Skive Festival case study.
- Form Follows Function. This is one of the most impressive HTML5/JavaScript playground I’ve seen.
- http://mountaindew.com/
- http://gooqx.com/
Start learning Greensock now
I’d suggest you get started with Jump Start: GSAP to quickly wrap your head around the Greensock Animation Platform. Once you’re done with that check out these resources:
I’d love to see your creations so share them in the comments.
Pingback: HTML5 Game Engines and Frameworks - PDG Technologies::Outsourcing company Smartphone Web Windows 8 Development
Pingback: Tutorial: Create Apple navigation using Greensock