Convert Figma logo to code with AI

CreateJS logoTweenJS

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

3,556
967
3,556
11

Top Related Projects

19,483

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

49,575

JavaScript animation engine

JavaScript/TypeScript animation engine

1,538

The fastest TypeScript animation engine on the web

JavaScript Sequence Editor

Quick Overview

TweenJS is a powerful animation and tweening library for JavaScript, part of the CreateJS suite. It provides a simple but robust API for creating and managing tweens and animations, making it easy to add smooth motion and transitions to web applications and interactive content.

Pros

  • Easy to use with a clean, intuitive API
  • Lightweight and performant, suitable for both desktop and mobile applications
  • Seamlessly integrates with other CreateJS libraries
  • Supports both time-based and frame-based animations

Cons

  • Limited built-in easing functions compared to some other tweening libraries
  • Lacks some advanced features found in more specialized animation libraries
  • Documentation could be more comprehensive and up-to-date
  • Not as actively maintained as some other popular animation libraries

Code Examples

Creating a simple tween:

createjs.Tween.get(myObject)
  .to({x: 300, y: 200}, 1000, createjs.Ease.quadOut)
  .call(handleComplete);

Chaining multiple tweens:

createjs.Tween.get(myObject)
  .to({alpha: 0}, 500)
  .to({x: 100}, 500)
  .to({alpha: 1}, 500);

Using a timeline for complex animations:

var tl = new createjs.Timeline();
tl.addTween(
  createjs.Tween.get(obj1).to({x: 200}, 1000),
  createjs.Tween.get(obj2).to({y: 300}, 1000)
);
tl.gotoAndPlay(0);

Getting Started

  1. Include the TweenJS library in your HTML file:
<script src="https://code.createjs.com/1.0.0/tweenjs.min.js"></script>
  1. Create a tween in your JavaScript code:
// Assuming you have an object named 'myObject'
createjs.Tween.get(myObject)
  .to({x: 100, y: 100}, 1000, createjs.Ease.linear)
  .call(function() {
    console.log("Tween complete!");
  });

// Don't forget to update the tween on each tick
createjs.Ticker.addEventListener("tick", function(event) {
  createjs.Tween.tick(event.delta, false);
});

This example creates a simple tween that moves myObject to the position (100, 100) over 1 second using linear easing, then logs a message to the console when complete. The ticker is set up to update the tween on each frame.

Competitor Comparisons

19,483

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

Pros of GSAP

  • More comprehensive animation features, including complex timelines and advanced easing functions
  • Better performance, especially for complex animations and large numbers of objects
  • Extensive plugin ecosystem for specialized animations (e.g., ScrollTrigger, MorphSVG)

Cons of GSAP

  • Steeper learning curve due to more advanced features and API
  • Larger file size, which may impact load times for smaller projects
  • Commercial license required for some use cases, unlike TweenJS's open-source MIT license

Code Comparison

TweenJS:

createjs.Tween.get(myObject)
  .to({x: 100, y: 200}, 1000, createjs.Ease.elasticOut)
  .call(handleComplete);

GSAP:

gsap.to(myObject, {
  x: 100,
  y: 200,
  duration: 1,
  ease: "elastic.out",
  onComplete: handleComplete
});

Both libraries offer similar basic functionality for tweening properties, but GSAP provides more options and flexibility in its API. GSAP's syntax is often more concise and intuitive, especially for complex animations. However, TweenJS integrates seamlessly with other CreateJS libraries, which can be advantageous for projects already using the CreateJS suite.

49,575

JavaScript animation engine

Pros of anime

  • Lightweight and standalone with no dependencies
  • Supports a wider range of animation targets (CSS, SVG, DOM, JavaScript objects)
  • More modern API with better performance

Cons of anime

  • Less mature ecosystem compared to TweenJS
  • Fewer built-in easing functions
  • Limited support for complex animation sequences

Code Comparison

TweenJS:

createjs.Tween.get(element)
  .to({x: 100, y: 200}, 1000, createjs.Ease.elasticOut)
  .call(handleComplete);

anime:

anime({
  targets: element,
  translateX: 100,
  translateY: 200,
  duration: 1000,
  easing: 'easeOutElastic',
  complete: handleComplete
});

Both libraries offer similar functionality for basic tweening, but anime provides a more concise and modern syntax. TweenJS uses a chaining approach, while anime uses a configuration object. anime's API is generally more flexible and easier to read, especially for complex animations.

TweenJS is part of the larger CreateJS suite, which can be advantageous if you're already using other CreateJS libraries. However, anime is more focused on animation specifically and may be a better choice for projects that don't require the full CreateJS ecosystem.

JavaScript/TypeScript animation engine

Pros of tween.js

  • Lightweight and standalone, with no dependencies
  • Supports a wider range of easing functions out-of-the-box
  • More active development and community support

Cons of tween.js

  • Less integrated with other animation tools compared to TweenJS
  • Lacks some advanced features like timeline management

Code Comparison

TweenJS:

createjs.Tween.get(target)
    .to({x: 300, y: 200}, 1000, createjs.Ease.elasticOut)
    .call(onComplete);

tween.js:

new TWEEN.Tween(target)
    .to({x: 300, y: 200}, 1000)
    .easing(TWEEN.Easing.Elastic.Out)
    .onComplete(onComplete)
    .start();

Both libraries offer similar syntax for basic tweening operations. TweenJS uses a chaining approach with the get() method, while tween.js creates a new Tween instance. The easing functions are applied differently, with TweenJS using createjs.Ease and tween.js using TWEEN.Easing. TweenJS combines the call() method for completion callbacks, whereas tween.js uses onComplete(). Overall, the syntax is quite similar, making it relatively easy to switch between the two libraries.

1,538

The fastest TypeScript animation engine on the web

Pros of Shifty

  • Lightweight and focused solely on tweening, making it more modular and potentially faster
  • Supports custom easing functions and allows for easy creation of new ones
  • Provides a more modern API with Promise support and better TypeScript integration

Cons of Shifty

  • Smaller community and less extensive documentation compared to TweenJS
  • Lacks some advanced features like timeline management found in TweenJS
  • May require additional libraries for more complex animations or integration with canvas-based projects

Code Comparison

Shifty:

import { tween } from 'shifty';

tween({
  from: { x: 0 },
  to: { x: 100 },
  duration: 1000,
  easing: 'easeInOutQuad',
  render: state => console.log(state.x)
});

TweenJS:

createjs.Tween.get(target)
  .to({ x: 100 }, 1000, createjs.Ease.quadInOut)
  .addEventListener("change", handleChange);

function handleChange(event) {
  console.log(target.x);
}

Both libraries offer straightforward APIs for creating tweens, but Shifty's approach is more functional and modern, while TweenJS is more object-oriented and integrated with the CreateJS suite.

JavaScript Sequence Editor

Pros of frame.js

  • Lightweight and minimalistic, focusing solely on animation timing
  • Provides a simple API for creating and managing animations
  • Easily integrates with other JavaScript libraries and frameworks

Cons of frame.js

  • Less feature-rich compared to TweenJS, with fewer built-in easing functions
  • Smaller community and fewer resources available for support
  • Limited documentation and examples

Code Comparison

TweenJS:

createjs.Tween.get(target)
  .to({x: 300, y: 200}, 1000, createjs.Ease.elasticOut)
  .call(handleComplete);

frame.js:

FRAME.Tween(target)
  .to({x: 300, y: 200}, 1000)
  .easing(FRAME.Easing.Elastic.Out)
  .onComplete(handleComplete);

Both libraries offer similar syntax for creating tweens, but TweenJS provides more built-in easing functions and a wider range of animation options. frame.js focuses on simplicity and core animation functionality, making it a good choice for projects that require lightweight animation capabilities. TweenJS, being part of the CreateJS suite, offers more robust features and better integration with other CreateJS libraries, making it suitable for more complex animation projects and interactive experiences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.

Example

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

var tween = createjs.Tween.get(myTarget)
    .to({x:300},400)
    .set({label:"hello!"})
    .wait(500).to({alpha:0,visible:false},1000)
    .call(onComplete);

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:

createjs.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.

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

Support and Resources

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.

Classes

Tween Returns a new Tween instance.

Timeline The Timeline class synchronizes multiple tweens and allows them to be controlled as a group.

Ease The Ease class provides a collection of easing functions for use with TweenJS. It does not use the standard 4 param easing signature. Instead it uses a single param which indicates the current linear ratio (0 to 1) of the tween.

Thanks

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

NPM DownloadsLast 30 Days