Giter Club home page Giter Club logo

tween.js's Introduction

tween.js

Javascript Tweening Engine

Flattr this

Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equations.

We are still developing this so the API might change from commit to commit.

Examples

Spline Simplest possible example Graphs Black and red Bars hello world

Projects using tween.js

ROME WebGL Globe Androidify Floweroscope The Wilderness Downtown Linechart

Usage

Download the minified library and include it in your html.

<script type="text/javascript" src="js/Tween.js"></script>

The following code creates a Tween which will change the 'x' attribute in a position variable, so that it goes from 50 to 400 in 2 seconds. The anonymous function set up with an interval will update the screen so that we can see something happening:

<script type="text/javascript">

	TWEEN.start();

	var output = document.createElement('div');
	var target = document.getElementById('target');
	target.appendChild(output);

	var position = {x: 50, y: 0};
	var tween = new TWEEN.Tween(position).to({x: 400}, 2000).onUpdate(update).start();

	function update() {

		var newX = position.x;

		output.innerHTML = 'x == ' + Math.round(newX);
		target.style.left = (newX) + 'px';

	};

</script>

Note: this corresponds to the example 04_simplest.html that you can find in the examples folder.

Have a look at that folder to discover more functionalities of the library!

Also, Jerome Etienne has written a tutorial demonstrating how to use tween.js with three.js, and it's also great for understanding how tweens work!

Frequently Asked Questions (FAQ)

Is there a way to control when is update() called? I'd like to use my own interval.
Yes, simply don't call TWEEN.start() and run TWEEN.update() in your own periodically executing function instead.
<dt>How do you set a tween to start after a while?</dt>
<dd>Use the delay() method: var t = new Tween({...}).delay(1000);</dd>

<dt>Is there a jQuery plug-in?</dt>
<dd>No, we like to keep it simple and free of dependencies. Feel free to make one yourself, though! :-)</dd>

Change log

2011 06 18 - r2

Added new utility methods getAll and removeAll for getting and removing all tweens (by Paul Lewis)

2011 05 18 - r1

  • Started using revision numbers in the build file
  • Consider this kind of an stable revision :-)

Contributors

People who have contributed directly or indirectly to this project :-D

sole, mrdoob, Robert Eisele, Robert Penner, Philippe Elsass, Paul Lewis

tween.js's People

Contributors

sole avatar mrdoob avatar paullewis avatar

Stargazers

Jordan Schiffer avatar

Watchers

Jordan Schiffer avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.