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

Overview

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.

Comments
  • Tweening 2+ objects cause page crashing after changing tabs

    Tweening 2+ objects cause page crashing after changing tabs

    I used the lastest version 1.0.2, when tweening 2+ objects then turned to a new tab, went back after a while the page became crashing. This problem would not be found with version 0.6.2. So now I have to use 0.6.2 again, waiting for fixing this problem.

    bug performance 
    opened by foreverpinetree 17
  • Impossible to stop tweens

    Impossible to stop tweens

    It seems to be impossible to stop/remove Tweens inbetween. In the latest version tweenjs_count is checked before removing tweens in Tween.removeTweens, however, this never seems to get set to more than 0..

    Note, I'm using the NEXT version.

    UTR 
    opened by Robinfr 12
  • Provide NPM package

    Provide NPM package

    It would be very convenient if TweenJS was available in the npm registry. I believe an increasingly common workflow is to manage both frontend and backend dependencies with npm, and use something like Browserify or Webpack to bundle your vendor dependencies for the frontend.

    Of the many frontend packages I routinely work with, TweenJS is in fact the last one I'm left pulling with Bower. If a npm package was available, I could finally ditch Bower completely.

    enhancement NextVersion 
    opened by tjunnone 8
  • TweenJS Color Plugin

    TweenJS Color Plugin

    Hi, I've created a plugin for the feature that I was really missing in TweenJS- color tweening. It can be used to tween colors in any format: RGB, HSL or Hex. Can tween fill color of: Shape, Text and Shadow, as well as other potential objects that might have the color property.

    • For colors defined in RGB or Hex format use: r, g, b tweening options.
    • For colors defined in HSL format use: h, s, l tweening options.

    Example of usage:

    createjs.ColorPlugin.install();
    ...
    shape1.graphics.beginFill("hsl(100, 50%, 80%)");
    shape2.graphics.beginFill("#FA1122");
    ...
    createjs.Tween.get(shape1).to({ h: 100, s: 90, l: 10 }, 500);
    createjs.Tween.get(shape2).to({ r: 200, b: 250 }, 1500);
    
    opened by mihhail-lapushkin 8
  • how to not create multiple rAF callbacks?

    how to not create multiple rAF callbacks?

    So I'm trying to integrate TweenJS into a team project. My PR is getting rejected because TweenJS creates multiple rAF callbacks per frame, as opposed to one single rAF callback per frame. I was wondering if that use case is supported? I think the useTicks options and tick method would do it, but it doesn't seem to animate correctly? I couldn't find any examples of how I might support that use case (but would be happy to send a PR with a new example once I figure it out). Is it possible for me to disable the Ticker class from creating multiple rAF calls, and instead be able to pass the time delta from my single rAF callback into a tween instance?

    question 
    opened by nickdesaulniers 7
  • Make Tween.get multiple targets

    Make Tween.get multiple targets

    It's nice to have multiple targets in Tween.get to reduce the number of lines in code:

    var target_a = new createjs.Shape();
    var target_b = new createjs.Shape();
    var targets = [target_a, target_b];
    
    createjs.Tween.get(targets, {loop:true}, true)
        .to({x: 300, y: 300}, 3000);
    
    // also support the following:
    createjs.Tween.get(target_a, {loop:true}, true)
        .to({x: 300, y: 300}, 3000);
    createjs.Tween.get(target_b, {loop:true}, true)
        .to({x: 300, y: 300}, 3000);
    
    enhancement 
    opened by watilde 7
  • Bug: memory leak when rendering is not taking place

    Bug: memory leak when rendering is not taking place

    I have tried this a few times on a powerful system, it's pretty easy to reproduce: I go to the tween demo click on a few ease types and leave the tab; after a few minutes, an "Aw, snap" shows up on that tab saying I need to free up more memory.

    Task manager and Timeline don't show noticeable memory leak while the tab is in focus. After switching to another tab it starts eating memory. Looks like there is a cleaning action that is triggered with rendering (requestAnimationFrame?).

    bug verified 
    opened by please-wait 6
  • "TWEEN is undefined"

    When I try to reference the TWEEN class in my code, I get an "Uncaught ReferenceError" saying that TWEEN is undefined. I have used the TweenJS CDN, the CreateJS CDN, the minified and the unminified file locally, and searched through countless examples to try and find out where I am going wrong. The line I get the error on is:

    var tween = new TWEEN.Tween(location);

    When I use the CreateJS CDN, the browser has no trouble with "new createjs...", but I just cannot get TweenJS to work.

    question 
    opened by aprilcarter 6
  • Tick listener and GetContext Error

    Tick listener and GetContext Error

    I'm using TweenJS and EaselJs installed using bower. I've encountered a problem recently where it seems the tick listener is calling the procedure this.canvas.getContext several times prompting this error:

    image

    Any suggestion?

    question 
    opened by ratuspro 5
  • How to use different timingMode in one project?

    How to use different timingMode in one project?

    Hi! I have 2 different components on my page. Each of them uses tween.js for animation, but one of them should work with Ticker.timingMode = Ticker.RAF and another one should work with Ticker.timingMode = Ticker.TIMEOUT. So as Ticker is a global variable, I have no idea how to implement this. Maybe, it's possible to call ticks manually for each component?

    enhancement 
    opened by holiber 5
  • Delayed Call order is backwards?

    Delayed Call order is backwards?

    Hi, if i set a bunch of delayed called, they appear to return in the incorrect order:

    p.loop = function () {
    for (var i = 0; i < 10; i ++) {
        // override can be true or false
        createjs.Tween.get( {}, {override : false} )
            .wait(  1000 )
            .call( this.printID, [ i ], this )
        }
    }
    
    p.printID = function ( id ) {
        console.log( id )
    }
    

    This then outputs:

    9
    8
    7
    6
    5
    4
    3
    2
    1
    0
    

    This is wrong right? First in should be first out.

    If I were to use TweenMax with the following code:

    TweenMax.delayedCall( 1.0, this.printID, [ i ], this );
    

    the results would be:

    0
    1
    2
    3
    etc...
    
    FOL bug 
    opened by aholla 5
  • Feature Request | Possibility request for adding a particular word different color in text class

    Feature Request | Possibility request for adding a particular word different color in text class

    I am trying to add color to a single word in the whole text that the user inputs in the Text class. text attribute but it changes the color of the whole text sentence and I am not finding any possible way to do that

    Is it possible to change the color of a particular word in the whole text sentence? Example: "Welcome to ADVR world" in this sentence inputted by the user I want to add a different color to "ADVR" and rest should be set to white color

    I tried this setting props in .set({color: 'red', text: 'ADVR'}) method but it removes the other text and adds only ADVR with red color

    I want the whole sentence in white and only ADVR in red.

    Is it possible to do that

    If Yes, please it would be a great help to me Thank you in advance. @gskinner

    opened by hiren3897 4
  • Tween loops get stuck when do update duration in the middle of the loop

    Tween loops get stuck when do update duration in the middle of the loop

    Hi,

    I do have infinitive Tween loop and i tried to change the duration for every loop ..It seems if you change duration property its get stuck any work around for this?

    Br, Gopi

    question 
    opened by msgopinath 1
  • HTML5 Canvas on Adobe Animate CC: Tweening any object to 0 causes all objects with mouse events to not respond anymore

    HTML5 Canvas on Adobe Animate CC: Tweening any object to 0 causes all objects with mouse events to not respond anymore

    I reported this as a bug to Adobe. Someone at the Adobe Community suggested to submit an issue here as well. Here's the bug report:

    1. Download and open the file in Adobe Animate CC. buttons.zip.
    2. Select the first frame in the "as" layer in the Timeline and open the Actions panel (Window > Actions).
    3. Go to code line 59 (it is a CreateJS Tween). Change the scaleX, scaleY and alpha values to 0, instead of 0.01.
    4. Test the project (Control > Test).
    5. Click on an image. A "window" opens with some info.
    6. Click on the orange circle with an "x" at the top right corner of the canvas.
    7. Move the cursor over an image and click.

    Results: The images don't respond to mouse events anymore. Expected results: The images should respond to the mouse when over, out and when clicked.

    verified 
    opened by johnpgranados 1
  • Tween._inited does not reset if scene is being destroyed or removed inside the game and rebuild

    Tween._inited does not reset if scene is being destroyed or removed inside the game and rebuild

    I have written a game using easeljs + preloadjs + soundjs + tweenjs. The scene order like this: I used the same canvas for different scene. Promo Scene -> Start Game Scene Every time finishing the game, the restart button will go to Promo Scene again.

    I found that probably(I haven't dig deep enough to find out) I use stage.clear(), stage.removeAllEventListeners() and so on. The Tween ticker is somehow being removed from the scene. So, first run, everything is fine, afterward, the Tween does not run unless I set Tween._inited = false before anything start again. Since the big Tween is supposed to be added once as tick function according to the source code logic.

    I add this in restart game logic createjs.Tween._inited = false; as workaround. Since_inited is undocumented due to it is an internal property.

    I think it is an issue for restarting everything, in the above situation, but not necessarily a bug.

    if (!Tween._inited && createjs.Ticker) {
    	console.log("init Tween");
    	createjs.Ticker.addEventListener("tick", Tween); Tween._inited = true; 
    }
    
    enhancement 
    opened by simongcc 1
  • bower install conflict

    bower install conflict

    Your name is in conflict with another package, can't seem to install your package via bower

    $ bower install TweenJS
    bower TweenJS#^0.6.2        not-cached https://github.com/sole/tween.js.git#^0.6.2
    bower TweenJS#^0.6.2           resolve https://github.com/sole/tween.js.git#^0.6.2
    bower TweenJS#*                 cached https://github.com/CreateJS/TweenJS.git#0.6.2
    bower TweenJS#*               validate 0.6.2 against https://github.com/CreateJS/TweenJS.git#*
    bower TweenJS#^0.6.2      ENORESTARGET No tag found that was able to satisfy ^0.6.2
    
    Additional error details:
    Available versions in https://github.com/sole/tween.js.git: 16.3.5, 16.3.4, 16.3.3, 16.3.2, 16.3.1, 16.3.0, 16.2.0, 16.1.1, 16.1.0
    
    $ bower install https://github.com/CreateJS/TweenJS.git
    bower TweenJS#*             not-cached https://github.com/CreateJS/TweenJS.git#*
    bower TweenJS#*                resolve https://github.com/CreateJS/TweenJS.git#*
    bower TweenJS#^0.6.2        not-cached https://github.com/sole/tween.js.git#^0.6.2
    bower TweenJS#^0.6.2           resolve https://github.com/sole/tween.js.git#^0.6.2
    bower TweenJS#*               download https://github.com/CreateJS/TweenJS/archive/0.6.2.tar.gz
    bower TweenJS#*                extract archive.tar.gz
    bower TweenJS#*           invalid-meta for:/tmp/peter/bower/c3e5c7552a2c79aab8799f5960525753-380-3HsIrX/bower.json
    bower TweenJS#*           invalid-meta The "name" is recommended to be lowercase, can contain digits, dots, dashes
    bower TweenJS#*               resolved https://github.com/CreateJS/TweenJS.git#0.6.2
    bower TweenJS#^0.6.2      ENORESTARGET No tag found that was able to satisfy ^0.6.2
    
    Additional error details:
    Available versions in https://github.com/sole/tween.js.git: 16.3.5, 16.3.4, 16.3.3, 16.3.2, 16.3.1, 16.3.0, 16.2.0, 16.1.1, 16.1.0
    
    $ bower install https://github.com/CreateJS/TweenJS.git --save --force
    bower TweenJS#*                resolve https://github.com/CreateJS/TweenJS.git#*
    bower EaselJS#^0.8.2           resolve https://github.com/CreateJS/EaselJS.git#^0.8.2
    bower TweenJS#*               download https://github.com/CreateJS/TweenJS/archive/0.6.2.tar.gz
    bower tween.js#^16.3.5         resolve https://github.com/sole/tween.js.git#^16.3.5
    bower TweenJS#^0.6.2           resolve https://github.com/sole/tween.js.git#^0.6.2
    bower EaselJS#^0.8.2          download https://github.com/CreateJS/EaselJS/archive/0.8.2.tar.gz
    bower tween.js#^16.3.5        download https://github.com/sole/tween.js/archive/v16.3.5.tar.gz
    bower TweenJS#*               progress received 0.8MB of 1.2MB downloaded, 72%
    bower TweenJS#*               progress received 1.0MB of 1.2MB downloaded, 85%
    bower TweenJS#*               progress received 1.2MB of 1.2MB downloaded, 99%
    bower TweenJS#*                extract archive.tar.gz
    bower EaselJS#^0.8.2          progress received 0.7MB
    bower tween.js#^16.3.5         extract archive.tar.gz
    bower tween.js#^16.3.5        resolved https://github.com/sole/tween.js.git#16.3.5
    bower TweenJS#*                  retry Decompression of archive.tar.gz failed with EACCES, trying with git..
    bower TweenJS#*               checkout 0.6.2
    bower EaselJS#^0.8.2          progress received 1.0MB
    bower EaselJS#^0.8.2          progress received 1.2MB
    bower EaselJS#^0.8.2          progress received 1.6MB
    bower EaselJS#^0.8.2          progress received 1.9MB
    bower EaselJS#^0.8.2          progress received 2.2MB
    bower TweenJS#^0.6.2      ENORESTARGET No tag found that was able to satisfy ^0.6.2
    
    Additional error details:
    Available versions in https://github.com/sole/tween.js.git: 16.3.5, 16.3.4, 16.3.3, 16.3.2, 16.3.1, 16.3.0, 16.2.0, 16.1.1, 16.1.0
    
    opened by pwmcintyre 0
Releases(1.0.0)
Owner
CreateJS
A suite of open source libraries and tools for building rich interactive content on open web technologies.
CreateJS
Lightweight JavaScript (ES6) tweening engine

Lightweight JavaScript (ES6) tweening library. EXAMPLES Examples collection DOCUMENTATION Purpose Install With npm Or fetch from CDN Basic usage Modul

Alexander Buzin 705 Dec 25, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Animation library build on top of web animation API (WAAPI)

unanime.js Javascript animation library build on top of web animation API (WAAPI). Learn more about WAAPI: Web animation API Documentation Blog Daniel

Clément Laval 3 Jun 21, 2022
A JavaScript animation plugin for menus. It creates a div that moves when you mouse over an element, giving it an elastic animation.

Lava-Lamp Description: A JavaScript animation plugin for menus. It creates a div that moves when you mouse over an element, giving it an elastic anima

Richard Hung 38 Jun 4, 2022
I made countdown birthday and fireworks animation using HTML Canvas, CSS, JS. The fireworks animation gonna come out once the countdown is finished or in other words, "Birthday Time".

Countdown-Birthday-Fireworks-Animation I made countdown birthday and fireworks animation using HTML Canvas, CSS, JS. The fireworks animation gonna com

Mahardika Bayu S.B 19 Dec 31, 2022
A simple but powerful tool to make your screenshots prettier.

SnipSnap A simple but powerful tool to make your screenshots prettier. Motivation I built SnipSnap because I wasn't happy with the other options as th

Faraz Patankar 15 Dec 16, 2022
A small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity

Wren Wren is a small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity. convenient aliases for HTTP responses au

Jakub Neander 69 Dec 12, 2022
🤪 A linter, prettier, and test suite that does everything as-simple-as-possible.

Features Fully Featured Code Grading Knowing if you need to work on your code is important- that's why we grade your code automatically. But, unlike o

Fairfield Programming Association 18 Sep 25, 2022
This is a TV shows list website. It is a capstone project that was completed as part of Module 2 - JavaScript.

Kanban Board Capstone Project This is a TV Shows web site source from TVmaze API. In the website, a user can click on heart icon and get it recorded i

Mayengbam Ranjit Luwang 7 Aug 11, 2022
Website to present projects made by me and that are part of my personal portfolio. It was made using React, HTML y Scss (CSS).

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Portfolio Jesús Leal 0 Dec 23, 2021
This is a project to testing coding habilities, it is part of the recruiting process of Liven.tech company

This is a project to testing coding habilities, it is part of the recruiting process of Liven.tech company

Romualdo 1 Feb 26, 2022
This project is part of the 2nd Module 2 Block of Microverse curriculum

To-do list is a tool that helps to organize our day. It simply lists the things that you need to do and allows you to mark them as complete by using ES6 and Webpack!

Ravi Teja 14 Mar 14, 2022
This is a basic website Todo Application that displays a list that looks and behaves like the part of minimalist project.

To-Do-list-microverse Description This is a basic website; a Todo Application that displays a list that looks and behaves like the part of minimalist

Dennis Akagha 7 Feb 3, 2022
Svaasthy project - a part of the Electrothon-4.0 Hackathon

Svaasthy View the presentaton The problems we address... The covid-19 crisis is drawing attention to the already overburdened public health systems in

PAVITRA BEHARA 5 Jun 16, 2022
Made this group project as a part of DESIS Ascend Educare Mentorship Program.

Buy-It-Right An intersection of Finance & Technology . About The Project: Buy It Right is a board game based on the economic idea of a monopoly. Four

Sejal Maheshwari 2 Dec 5, 2022
The cloud computing part required by the Rebage application ☁

Rebage - Cloud Computing The cloud technology used in Rebage Powered by: Google Cloud Platform, offered by Google, is a suite of cloud computing servi

Rebage Bangkit 2022 3 Sep 25, 2022