Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@createjs/tweenjs

createjs9.8kMIT2.0.0-beta.4

A simple but powerful tweening / animation library for Javascript. Part of the CreateJS suite of libraries.

html5, canvas, tween, tweenjs, createjs, gskinner, flash, animate, animation

readme

2.0 BETA

This branch is in beta. Reporting issues is appreciated, please mention that it is for 2.0 in the issue body.

Unit tests failing is a known issue, please don't report this.

Plugin architecture is incomplete, as such they are expected to break.

tweenjs

TweenJS is a simple tweening library for use in JavaScript. It was developed to integrate well with the EaselJS library, but is not dependent on or specific to it (though it uses the same Ticker and Event classes by default). It supports tweening of both numeric object properties & CSS style properties.

Installation

NPM

npm install @createjs/tweenjs --save

CDN

<script src="https://code.createjs.com/2.0/tweenjs.min.js"></script>

Simple Example

The API is simple but very powerful, making it easy to create complex tweens by chaining commands.

import { Tween } from "@createjs/tweenjs";
let tween = Tween.get(target)
    .to({ x: 300 }, 400)
    .set({ label: "hello!" })
    .wait(500)
    .to({ alpha: 0, visible: false }, 1000)
    .call((p1, p2) => { ... }, [ 10, true ]); // p1 === 10, p2 === true, this === target

The example above will create a new Tween instance that:

  • tweens the target to an x value of 300 over 400ms and sets its label to "hello!"
  • waits 500 ms
  • tweens the target's alpha to 0 over 1s & sets its visible to false
  • calls the onComplete function

Tweens are composed of two elements: steps and actions.

Steps define the tweened properties and always have a duration associated with them (even if that duration is 0). Steps are defined with the "to" and "wait" methods. Steps are entirely deterministic. You can arbitrarily set a tween's position, and it will always set the same properties for that position.

Actions do not have a duration, and are executed between steps. They are defined with the call(), set(), play(), and pause() methods. They are guaranteed to execute in the correct order, but not at the precise moment in time that is indicated in the sequence. This can lead to indeterminate results, especially when tweens are interacting via the play and pause actions.

Tweens support a number of configuration properties, which are specified as the second param when creating a new tween:

Tween.get(target, {
    loop: true,
    useTicks: true,
    css: true,
    ignoreGlobalPause: true
}).to(etc...);

All configuration properties default to false. The properties are:

loop - indicates whether the tween should loop when it reaches the end

useTicks - the tween will use ticks for duration instead of milliseconds

css - enables css mapping for some css properties

ignoreGlobalPause - the tween will continue ticking even when Ticker is paused.

When using Tween.get(), you can also specify true as the third parameter to override any active tweens on the target.

Tween.get(target, null, true); // this will remove any existing tweens on the target.

Support and Resources

  • Find examples and more information at the TweenJS web site.
  • Read the documentation.
  • Discuss, share projects, and interact with other users on reddit.
  • Ask technical questions on Stack Overflow.
  • File verified bugs or formal feature requests using Issues on GitHub.
  • There is a Google Group for discussions and support.
  • Have a look at the included examples for more in-depth instructions.

It was built by gskinner.com, and is released for free under the MIT license, which means you can use it for almost any purpose (including commercial projects). We appreciate credit where possible, but it is not a requirement.

Thanks

Special thanks to Robert Penner for his easing equations, which form the basis for the Ease class.

changelog

Version NEXT [not yet released]


CRITICAL (may break existing content):

  • Plugin model has changed significantly. See SamplePlugin for information.
  • Second param of Tween/Timeline.setPosition() is now runActions boolean
  • Removed Tween.NONE, Tween.LOOP, and Tween.REVERSE constants
  • pluginData is now a property in the props param, instead of its own param
  • Removed Tween.installPlugin, in favour of Plugin.install()
  • Removed Tween.tick (instance) in favour of Tween.advance
  • Tween actions in a Timeline now run after all the tween properties are updated
  • added check for hasOwnProperty on tween properties to filter out inherited properties

DEPRECATED (will break in the future):

  • Timeline constructor now expects a single param props, which now supports tweens and labels properties
  • to make a tween loop continuously, you should now use loop:-1, instead of loop:true
  • setPaused deprecated in favor of paused getter / setter
  • getCurrentLabel deprecated in favor of currentLabel getter / setter

OTHER:

  • Very significant performance improvements to Tween and plugins
  • Plugin model is now much more powerful / flexible.
  • Tween and Timeline now extend AbstractTween
  • Tween and Timeline now have more similar/consistent interfaces
  • Added Tween.reversed and Tween.bounce properties (also on Timeline)
  • Tween.loop now supports setting a numeric loop count value (also on Timeline)
  • Added Tween.rawPosition and Tween.useTicks read-only properties (also on Timeline)
  • Timeline now removes tweens from other timelines when adding them
  • Tween and Timeline now extend AbstractTween
  • Added .label() to Tween
  • Tweens now support getLabels(), addLabel(), setLabels(), gotoAndPlay(), gotoAndStop(), and resolve()
  • Added .label() to Tween
  • Added Tween.timeScale & Timeline.timeScale
  • Added ColorPlugin, RelativePlugin, and RotationPlugin
  • CSSPlugin now works with any style value, and can optionally use computed styles
  • fixed issues with zero length tweens
  • action execution is now correct for tweens in timelines with looping
  • Timeline.tweens added
  • improvements / additions to examples
  • added callback param to setPosition for MovieClip use
  • fixed a bug with Tween.set()
  • unit tests made somewhat more robust

Version 0.6.2 [November 26, 2015]


  • fixed MotionGuidePlugin handling of empty data
  • solved memory leak in SparkTable demo
  • documentation and example updates

Version 0.6.1 [May 21, 2015]


  • Fixed an issue with Tween.removeAllTweens and tweens with no target
  • Fixed an issue that could cause tweens to be ticked multiple times per tick

Version 0.6.0 [December 12, 2014]


CRITICAL (may break existing content):

  • Added Ticker into the "createjs" package to remove reliance on EaselJS.
  • re-architected the class and inheritance model
    • initialize methods removed, use MySuperClass_constructor instead
    • helper methods: extend & promote (see the "Utility Methods" docs)
    • property definitions are now instance level, and in the constructor (performance gains)
    • the .constructor is now set correctly on all classes (thanks kaesve)

OTHER:

  • Added bower support, including grunt task for updating the bower.json
  • Fixed issue with setPaused() stacking up tween ticks
  • Added .gitignore to subfolders under /docs (thanks mcfarljw)
  • Improved EventDispatcher's handling of redispatched event objects
  • Fixed "none" Ease

Version 0.5.1 [December 12, 2013]


  • Updates to EventDispatcher for latest combined build

Version 0.5.0 [September 25, 2013]


CRITICAL (may break existing content):

  • removed all onEvent handlers (ex. onClick, onTick, onAnimationEnd, etc)

  • implemented createjs Utils
  • implemented "use strict" mode
  • added "passive" param to Tween.wait()
  • updates to MotionGuidePlugin
  • Documentation
    • Added note in the documentation on the dependency on EaselJS Ticker.
    • Added note on CSSPlugin not being included in minified versions
    • Formatted JSDoc comment blocks
    • Added note in code on static initialization of Ticker
  • Swapped indexOf usages for inline for loops (for IE8 support)
  • Updated Ticker usage to use EventDispatcher instead. Added handleEvent to propagate tick event
  • Added TweenOnlyDemo to show TweenJS usage without EaselJS
  • Fixed incorrectly doc'd Timeline documented put all Timeline APIs into Tween instead.
  • fixed an issue with EventDispatcher when adding the same listener to an event twice
  • fixed hasActiveTweens to return a Boolean consistently
  • added Timeline.getLabels() & getCurrentLabel()
  • Tween waits to add itself as a listener on Ticker until the first tween is started
  • Updated the build process to use NodeJS & Grunt.js. Please refer to the readme in the build folder.

Version 0.4.1 [May 10, 2013]


  • Fixed tween reference in a game loop of Timeline.
  • Added additional examples and documentation to Tween
  • Updated examples to propagate the tick event to the stage
  • Documented optional parameters in Tween.get()
  • Updated to latest EventDispatcher
  • Added Tween.removeAllTweens method

Version 0.4.0 [Feb 12, 2013]


  • added EaselJS EventDispatcher capabilities to TweenJS
  • updated build process to use NodeJS
  • added tween_version.js, which generates a TweenJS object at run time that contains build information
  • updated documentation descriptions, examples, and style
  • added MotionGuidePlugin to support Toolkit for CreateJS

Version 0.3.0 [Aug 27, 2012]


  • moved all class definitions into a configurable "createjs" namespace
  • fix for a race condition that can arise when one tween causes others to be removed
  • added Tween.hasActiveTweens(target)
  • fixed issue with minified version of code being dependent on Ticker
  • fixed issue with unpausing tweens after adding & removing from a Timeline
  • added .onChange() to Tween & Timeline
  • added .position to Tween & Timeline
  • added Tween.target

Version 0.2.0 [Apr 13, 2012]


  • implemented a plugin model, and moved CSS support to CSSPlugin
  • Timeline now forces its useTicks setting on child tweens
  • can set paused & position in config props
  • fix for negative positions in tweens
  • added Timeline.resolve()
  • minor bug fixes and doc updates

Version 0.1.0 [Nov 28, 2011]


Initial release.