# tween.js JavaScript (TypeScript) tweening engine for easy animations, incorporating optimised Robert Penner's equations. [![NPM Version][npm-image]][npm-url] [![CDNJS][cdnjs-image]][cdnjs-url] [![NPM Downloads][downloads-image]][downloads-url] [![Build and Tests][ci-image]][ci-url] More languages: [English](./README.md), [简体中文](./README_zh-CN.md) --- ```html
``` [Try this example on CodePen](https://codepen.io/trusktr/pen/KKGaBVz?editors=1000) # Installation ## From CDN Install from a content-delivery network (CDN) like in the above example. From cdnjs: ```html ``` Or from unpkg.com: ```html ``` Note that unpkg.com supports a semver version in the URL, where the `^` in the URL tells unpkg to give you the latest version 20.x.x. ## Build and include in your project with script tag Currently npm is required to build the project. ```bash git clone https://github.com/tweenjs/tween.js cd tween.js npm install npm run build ``` This will create some builds in the `dist` directory. There are currently two different builds of the library: - UMD : `tween.umd.js` - ES6 Module : `tween.es.js` You are now able to copy tween.umd.js into your project, then include it with a script tag, which will add TWEEN to the global scope, ```html ``` or import TWEEN as a JavaScript module, ```html ``` where `path/to` is replaced with the location where you placed the file. ## With `npm install` and `import` from `node_modules` You can add tween.js as an npm dependency: ```bash npm install @tweenjs/tween.js ``` ### With a build tool If you are using [Node.js](https://nodejs.org/), [Parcel](https://parceljs.org/), [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Vite](https://vitejs.dev/), or another build tool, then you can now use the following to include tween.js: ```javascript import * as TWEEN from '@tweenjs/tween.js' ``` ### Without a build tool You can import from `node_modules` if you serve node_modules as part of your website, using an `importmap` script tag. First, assuming `node_modules` is at the root of your website, you can write an import map: ```html ``` Now in any of your module scripts you can import it by its package name: ```javascript import * as TWEEN from '@tweenjs/tween.js' ``` # Features - Does one thing and one thing only: tween properties - Doesn't take care of CSS units (e.g. appending `px`) - Doesn't interpolate colors - Easing functions are reusable outside of Tween - Can also use custom easing functions # Documentation - [User guide](./docs/user_guide.md) - [Contributor guide](./docs/contributor_guide.md) - [Tutorial](https://web.archive.org/web/20220601192930/http://learningthreejs.com/blog/2011/08/17/tweenjs-for-smooth-animation/) using tween.js with three.js - Also: [libtween](https://github.com/jsm174/libtween), a port of tween.js to C by [jsm174](https://github.com/jsm174) # Examples
|
hello world (source) |
|
Bars (source) |
|
Black and red (source) |
|
Graphs (source) |
|
Simplest possible example (source) |
|
Video and time (source) |
|
Array interpolation (source) |
|
Dynamic to, object (source) |
|
Dynamic to, interpolation array (source) |
|
Dynamic to, large interpolation array (source) |
|
Repeat (source) |
|
Relative values (source) |
|
Yoyo (source) |
|
Stop all chained tweens (source) |
|
Custom functions (source) |
|
Relative start time (source) |
|
Pause tween (source) |
|
Complex properties (source) |
|
Animate an array of values (source) |
](https://lume.io)
[](https://aframe.io)
[](http://www.moma.org/interactives/exhibitions/2012/inventingabstraction/)
[](http://www.chromeweblab.com/)
[](http://5013.es/toys/macchina)
[](http://egraether.com/mine3d/)
[](http://ro.me)
[](http://data-arts.appspot.com/globe)
[](http://www.androidify.com/)
[](http://thewildernessdowntown.com/)
[](http://dejavis.org/linechart)
[npm-image]: https://img.shields.io/npm/v/@tweenjs/tween.js.svg
[npm-url]: https://npmjs.org/package/@tweenjs/tween.js
[downloads-image]: https://img.shields.io/npm/dm/@tweenjs/tween.js.svg
[downloads-url]: https://npmjs.org/package/@tweenjs/tween.js
[ci-image]: https://github.com/tweenjs/tween.js/workflows/build%20and%20tests/badge.svg?branch=master
[ci-url]: https://github.com/tweenjs/tween.js/actions
[cdnjs-image]: https://img.shields.io/cdnjs/v/tween.js.svg
[cdnjs-url]: https://cdnjs.com/libraries/tween.js