Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

GSAP JS 1.9.0 Released

| GreenSock

Note: This page was created for GSAP version 2. We have since released GSAP 3 with many improvements. While it is backward compatible with most GSAP 2 features, some parts may need to be updated to work properly. Please see the GSAP 3 release notes for details.


New DirectionalRotationPlugin

Have you ever tweened rotation to a particular value but wished that you could control which direction it traveled (clockwise or counter-clockwise)? For example, if the current rotation is 170 and you tween to -170, normally that would travel counter-clockwise -340 degrees but what if you prefer rotating 20 degrees clockwise instead? Or maybe you just want it to go in the shortest direction to that new position (20 degrees in this case). This is all possible now with the DirectionalRotationPlugin.

Previously, shortRotation was available in CSSPlugin, but there were three shortcomings (pardon the pun):

  1. It always went in the shortest direction - it wasn't possible to define a particular direction (clockwise or counter-clockwise).
  2. It required using a different property name ("shortRotation" or "shortRotationX" or "shortRotationY") instead of the regular property name ("rotation" or "rotationX" or "rotationY").
  3. It only worked on DOM elements. What if you have a generic object or an EaselJS Shape (or whatever)?

The new DirectionalRotationPlugin solves all of these issues. First of all, its functionality is baked into CSSPlugin, so you don't even need to load the DirectionalRotationPlugin if you're only animating DOM elements. The plugin is also included in TweenMax, so there's no need to load a separate plugin there either.

Use the new syntax to get the desired behavior - add one of the following suffixes to the value: "_cw" for clockwise, "_ccw" for counter-clockwise, and "_short" to go whichever direction is shortest. Here are some examples:

//tweens to the 270 position in a counter-clockwise direction (notice the value is in quotes) 
TweenMax.to(element, 1, {rotation:"270_ccw"}); 

//tweens to the -45 position in a clockwise direction 
TweenMax.to(element, 1, {rotation:"-45_cw"}); 

//tweens 1.5 radians more than the current rotationX value, and travels in the shortest direction 
TweenMax.to(element, 1, {rotationX:"+=1.5rad_short"});

If you're tweening a more generic object (anything that's not a DOM element), you can use the DirectionalRotationPlugin. If you pass in a simple value, it will assume you're attempting to tween the target's "rotation" property but you can tween ANY rotational properties of any name by passing in an object with the appropriate properties. Here are some examples:

//start with a generic object with various rotation values
var obj = {rotation:45, rotationX:0, rotationY:110};

//tweens rotation to 270 in a clockwise direction
TweenLite.to(obj, 1, {directionalRotation:"270_cw"});

//tweens rotationX to -45 in a counter-clockwise direction and rotationY to 200 in a clockwise direction:
TweenLite.to(obj, 1, {directionalRotation:{rotationX:"-45_ccw", rotationY:"200_cw"}});

As of 1.9.0, shortRotation is deprecated in favor of this new (more flexible and concise) syntax.

New AttrPlugin

This plugin allows you to tween any numeric attribute of a DOM element. For example, let's say your DOM element looks like this:

<rect id="rect" fill="none" x="0" y="0" width="500" height="400"></rect>

You could tween the "x", "y", "width", or "height" attributes using AttrPlugin like this:

//tuck any attributes you want to tween into an attr:{} object
TweenMax.to("#rect", 1, {attr:{x:100, y:50, width:100, height:100}, ease:Linear.easeNone});

You can tween an unlimited number of attributes simultaneously. Just use the associated property name inside the attr:{} object. The AttrPlugin is included inside the TweenMax JS file, so you don't need to load the plugin separately if you're using TweenMax.

New TextPlugin

This plugin allows you to tween the text content of a DOM element, replacing it one character at a time (or one word at a time if you set the delimiter to " " (a space) or you can even use a custom delimiter). So when the tween is finished, the DOM element's text has been completely replaced. This also means that if you rewind/restart the tween, the text will be reverted to what it was originally.

Here is a simple example of replacing the text in yourElement:

//replaces yourElement's text with "This is the new text" over the course of 2 seconds
TweenMax.to(yourElement, 2, {text:"This is the new text", ease:Linear.easeNone});

If you'd like to use a different delimiter so that instead of replacing character-by-character, it gets replaced word-by-word, just pass an object with configuration properties like this:

//replaces word-by-word because the delimiter is " " (a space)
TweenMax.to(yourElement, 2, {text:{value:"This is the new text", delimiter:" "}, ease:Linear.easeNone});

Sometimes it's useful to have the new text differentiated visually from the old text, so TextPlugin allows you to assign a css class to the new and/or old content, like this:

//wraps the old text in <span class="class1"></span> and the new text in a <span class="class2"></span>
TweenLite.to(yourElement, 2, {text:{value:"This is the new text", newClass:"class2", oldClass:"class1"}, ease:Power2.easeIn});

As indicated, defining a newClass and/or oldClass will result in wrapping a <span> tag around the associated text. The TextPlugin is NOT included inside TweenMax, so you'll need to load it separately.

Other updates and enhancements in 1.9.0:

  1. Added support for hsl() and hsla() colors in CSSPlugin and ColorPropsPlugin
  2. Implemented a new (more concise and clear) way to register plugins. Old plugins will still work fine, but most of the new ones in 1.9.0 use the new style of registering which won't work with old versions of TweenLite/TweenMax. Please just make sure all your files are updated.
  3. Fixed issue that caused className to be ignored by the autoCSS feature that creates the css:{} wrapper internally.
  4. Fixed issue that could cause em not to be translated to px accurately, causing a jump when the start and end units for the tween don't match (like px to em or visa-versa)
  5. Fixed backfaceVisibility so that it is properly prefixed when necessary
  6. Now setting "float" on a DOM element will work across browsers including Firefox and IE.
  7. Worked around issue that caused x/y/z transforms not to work properly if they exceeded 21,474 (or -21,474).
  8. Fixed issue that caused values not to be interpreted correctly if a negative number had a relative prefix, like "+=-50px" or "-=-50px"
  9. Fixed issue in EaselPlugin that prevented ColorMatrixFilter tweens from working correctly when the starting matrix wasn't an identity matrix
  10. Now fromTo() and staggerFromTo() methods have immediateRender set to true by default, just like from() and staggerFrom() always did. This seems like the preferred behavior for most developers, but you can certainly set immediateRender:false on any tween if you prefer that behavior.
  11. Now fromTo() and staggerFromTo() tweens that have immediateRender:false will record their pre-tween values (before even implementing the "from" part of the tween) so that if their parent timeline rewinds past the beginning of the tween, it restores values to their originals.

Get it now

Download the latest version of GSAP using the fancy new download screen, and notice that everything is also available as CDN links as well. The docs have been updated to reflect all these changes.


Swing by the forums to get your questions answered.

Get an all-access pass to premium plugins, offers, and more!

Join the Club

With great power comes great responsibility. Tween wisely.

- Team GreenSock

User Feedback

Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now