jQuery.animate() with GSAP? Introducing jquery.gsap.js plugin
Good news for anyone using jQuery.animate() – the new jquery.gsap.js plugin allows you to have GSAP take control under the hood so that your animations perform better; no need to change any of your code. Plus GSAP adds numerous capabilities, allowing you to tween colors, 2D transforms (rotation, scaleX, scaleY, skewX, skewY, x, y), 3D transforms (rotationX, rotationY, z, perspective), backgroundPosition, boxShadow, and lots more. You can even animate to a different className!

This plugin makes it very easy to audition GSAP in your project without needing to learn a new API. We still highly recommend learning the regular GSAP API because it’s much more flexible, robust, and object-oriented than jQuery.animate(), but for practical purposes this plugin delivers a bunch of power with almost zero effort.
Benefits
- Up to 20x faster than jQuery’s native animate() method. See the interactive speed comparison for yourself.
- Works exactly the same as the regular jQuery.animate() method. Same syntax. No need to change your code. Just load the plugin (and TweenMax or TweenLite & CSSPlugin) and you’re done.
- Adds the ability to animate additional properties (without vendor prefixes):
- colors (backgroundColor, borderColor, color, etc.)
- boxShadow
- textShadow
- 2D transforms like rotation, scaleX, scaleY, x, y, skewX, and skewY, including 2D transformOrigin functionality
- 3D transforms like rotationY rotationX, z, and perspective, including 3D transformOrigin functionality
- borderRadius (without the need to define each corner and use browser prefixes)
- className which allows you to define a className (or use “+=” or “-=” to add/remove a class) and have the engine figure out which properties are different and animate the differences using whatever ease and duration you want.
- backgroundPosition
- clip
- Animate along Bezier curves, even rotating along with the path or plotting a smoothly curved Bezier through a set of points you provide (including 3D!). GSAP’s Bezier system is super flexible in that it’s not just for x/y/z coordinates – it can handle ANY set of properties. Plus it will automatically adjust the movement so that it’s correctly proportioned the entire way, avoiding a common problem that plagues Bezier animation systems. You can define Bezier data as Cubic or Quadratic or raw anchor points.
- Add tons of easing options including proprietary SlowMo and SteppedEase along with all the industry standards
- When animating the rotation of an object, automatically go in the shortest direction (clockwise or counter-clockwise) using shortRotation, shortRotationX, or shortRotationY
For a detailed comparison between jQuery and GSAP, check out the cage match.
Usage
Download the files (requires version 1.8.0 (or later) of TweenMax or TweenLite!) and then add the appropriate script tags to your page. The plugin file (jquery.gsap.min.js) itself does NOT include GSAP because you get to choose which files you want to load depending on the features you want. The simplest way to get all the goodies is by loading TweenMax (which includes TweenLite, CSSPlugin, TimelineLite, TimelineMax, EasePack, BezierPlugin, and RoundPropsPlugin too). For example, assuming you put the TweenMax.min.js file into a folder named “js” which is in the same directory as your HTML file, you’d simply place the following code into your HTML file:
All the goodies:
<script src="js/TweenMax.min.js"></script> <script src="js/jquery.gsap.min.js"></script>
If, however, you’re more concerned about file size and only want to use TweenLite, CSSPlugin (for animating DOM elements), and some extra eases, here is a common set of script tags:
Lightweight:
<script type="text/javascript" src="js/plugins/CSSPlugin.min.js"></script> <script src="js/easing/EasePack.min.js"></script> <script src="js/TweenLite.min.js"></script> <script src="js/jquery.gsap.min.js"></script>
Then, to animate things, you can use the regular jQuery.animate() method like this:
//tween all elements with class "myClass" to top:100px and left:200px over the course of 3 seconds
$(".myClass").animate({top:100, left:200}, 3000);
//do the same thing, but with a Strong.easeOut ease
$(".myClass").animate({top:100, left:200}, {duration:3000, easing:"easeOutStrong"});
//tween width to 50% and then height to 200px (sequenced) and then call myFunction
$(".myClass").animate({width:"50%"}, 2000).animate({height:"200px"}, {duration:3000, complete:myFunction});
See jQuery’s API docs for details about the syntax and options available with the animate() method. And yes, the jQuery.stop() method works too.
Caveats
- If you define any of the following in the animate() call, it will revert to the native jQuery.animate() method in order to maximize compatibility (meaning no GSAP speed boost and no GSAP-specific special properties will work in that particular call):
- a “step” function – providing the parameters to the callback that jQuery normally does would be too costly performance-wise. One of the biggest goals of GSAP is optimized performance; We’d strongly recommend NOT using a “step” function for that reason. Instead, you can use an onUpdate if you want a function to be called each time the values are updated.
- Anything with a value of “show”, “hide”, “toggle”, “scrollTop” or “scrollLeft”. jQuery handles these in a unique way and we don’t want to add the code into CSSPlugin that would be required to support them natively in GSAP.
- If skipGSAP:true is found in the “properties” parameter, it will force things to fall back to the native jQuery.animate() method. So if a particular animation is acting different than what you’re used to with the native jQuery.animate() method, you can just force the fallback using this special property. Like
$(".myClass").animate({scrollTop:200, skipGSAP:true});
- This is our first crack at a jQuery plugin, so please let us know if anything breaks or if you have ideas for improvement.
FAQ
Stay up to date
We’d highly recommend checking back frequently and keeping your files updated because we’re constantly adding features, patching bugs, implementing workarounds for new browser inconsistencies, etc. Sign up for a free GreenSock account so that you’re on our mailing list and get important notifications. Don’t forget to follow us on Twitter as @greensock and Facebook too.
Need help?
There are dedicated forums for all GreenSock tools at http://forums.greensock.com/. Keep in mind that you’ll increase your chances of getting a prompt answer if you provide a brief explanation and include a simplified HTML file (and any dependencies) that clearly demonstrates the problem with as little code as possible.
Recommended reading:
- Main GSAP JS page (with downloads)
- Jump Start: GSAP JS
- jQuery vs GSAP: cage match
- Speed comparison
- 3D Transforms & More CSS3 Goodies Arrive in GSAP JS
- jQuery.animate() docs
Comments (19)

just wow! you kill it yet again!!
Thank you for your great plugin. This is what I exactly needed for my latest project. I’m using jquery Isotope too animating heavy scale elements in my page and I could not change the animate function manually. You could not imagine how much this plugin improve my animation.
I tested it, but the only problem is my scroll animation stopped working.
I still didn’t checked it out that where the problem is, but I’m sure that this one is too gonna solve.
Hi. Thanks for your quick reply.
I found that first of all I didn’t import the ScrollToPlugin as I thought TweenMax has all the GSAP plugins.
But the problem was still there. I found that the selector object for scrolling the whole page in GSAP is different from jQuery.
I used $(‘html,body’).animate({scrollTop:destY}); for scrolling the page. But It could not transform it GSAP.
I even used these solutions :
(1) :
To see if it transform it individually.
$(‘html’).animate({scrollTop:destY});
$(‘html’).animate({scrollTop:destY});
(2) :
To see if it just works with TweenMax or not.
TweenMax.to($(‘html’),0.3,{scrollTop:destY});
TweenMax.to($(‘body’),0.3,{scrollTop:destY});
None of above solutions worked for me.
At last I decided to not wait for the jquery.gsap plugin to transform my animation (in just this particular subject “Scrolling” the page) and simply just used this :
TweenMax.to(window,0.3,{scrollTo:{y:destY}});
Problem solved ![]()
I don’t know if it’s me that missing something or that’s the only way to do it.
Thank you
Farzan, I think you probably meant to do this:
$(window).animate({scrollTo:destY});
Just make sure you load the ScrollToPlugin as well (as you discovered). We don’t include ALL plugins in TweenMax because I fear it’ll just get too big as we come out with more and more plugins. So we cover a lot of the common basics inside TweenMax.
Wow, big jump. Congratulations.
Hi,
which would be faster?
$(“#myDiv”).animate({top:100, left:200},2000);
or
TweenLite.to(“#myDiv”, 2, {top:100, left:200});
The native TweenLite method(s) would be slightly faster just because there’s less parsing required (it doesn’t have to translate the jQuery.animate() data into GSAP format). See FAQ 2.
The best animation platform in the world! Thanks for your hard work! You rock the world of web (and not only) animation!
Looking forward to giving this a whirl! Have you noticed any browser compatibility issues that should be noted?
No, Justin, we’re not aware of any browser compatibility issues at this point. Let us know if you find something, though.
I don’t suppose you could update the speed comparison test to have a jQuery animate + GSAP option? That’d be awesome!
Sure, jquery.gsap.js was just added to the speed test. Enjoy!
Anyone tried this with Adobe Edge (with timeline not code animations)?
great work jack!
Hi all. I’ve got 2 questions:
1. Is this plugin work only for jquery animate function? Or work with other jquery functions too? (scroll to, hide/show, fade…)
2. In which order should I load libraries? In example I have: gsap files, jquery, jquery libraries, other libraries like nice scroll or flexslider
1) It works on anything that flows through the jQuery.animate() method except things that use jQuery-specific “show”, “hide”, “toggle”, (actualy, “scrollTop” and “scrollLeft” too because jQuery handles them in a non-standard way).
2) As long as you load jQuery before the plugin, you should be fine. GreenSock files themselves have code in place that handles loading them in any order, but since the jquery.gsap.js plugin builds on jQuery, jQuery must be loaded first.
Does it support -= and += to animate values relatively? I can’t seem to make that work.
Also I used skewX and in IE 6/7/8 the element seemed to try to skew but it was clipped inside a container.
Yes, ace, it definitely supports +=/-= relative values. And the skew clipping you saw in IE6-8 is because you didn’t set position to absolute (old versions of IE force the clipping otherwise). If you’re still having trouble, please don’t hesitate to post in the forums at http://forums.greensock.com. I’d love to see a sample codepen/jsfiddle/file that demonstrates the problem(s). I just tested the +=/-= relative stuff and it worked as expected. Make sure you’re using the latest version of the GSAP files too.
the +=/-= problem was that I was e.g. using “-=20px” instead of “-=20″
Also could this plugin be expanded to include the jquery .css() function?
It could be useful for resetting CSS transition/box-shadow etc. properties without having to do animate() with 1 msec.
ace, it’s fine to use units in the relative values, like “-=20px”. I’d be curious to see an example of where that wasn’t working for you.
As for including the jQuery.css() function, that’s tricky because it would have to provide “get” capabilities too (not just “set”) for everything, and that can be non-trivial when dealing with special stuff like individual transforms (scaleX/scaleY/x/y/z/rotation/rotationX/etc.), or things like scrollTo, etc. And then there’s the fact that jQuery has some special properties that it handles in a unique way too, so it’s not as easy as just feeding stuff to GSAP. We’ll definitely keep this in mind as a potential future enhancement though. It isn’t impossible, for sure. We appreciate the feedback/suggestion.




















Download zip