<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-21603807</id><updated>2012-01-20T22:25:43.867+01:00</updated><title type='text'>JAVASCRIPT MOTION TWEEN</title><subtitle type='html'>Javascript animation engine</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jstween.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21603807/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://jstween.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>pim Maegerman</name><uri>https://profiles.google.com/102069174973969560746</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-rQRPm8io5bc/AAAAAAAAAAI/AAAAAAAAd00/MVQFwwqm3OQ/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-21603807.post-113840530720686868</id><published>2007-01-28T00:21:00.011+01:00</published><updated>2010-04-15T09:55:54.010+02:00</updated><title type='text'>Javascript Motion Tween</title><content type='html'>&lt;ul style="list-style: none;"&gt;&lt;li&gt;&lt;a href="#Tween"&gt;Tween&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#TweenConstructor"&gt;Constructor&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#TweenMethods"&gt;Methods&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#TweenMethodsEx"&gt;Example&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="#TweenEasing"&gt;Easing functions&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://jstween.sourceforge.net/moveSquare.html" target="_blank"&gt;Example&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="#TweenEvents"&gt;Events&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#TweenEventListeners"&gt;Events listeners&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="#ColorTween"&gt;ColorTween&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#ColorTweenConstructor"&gt;Constructor&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#ColorTweenEx"&gt;Example&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="#OpacityTween"&gt;OpacityTween&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#OpacityTweenConstructor"&gt;Constructor&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#OpacityTweenEx"&gt;Example&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="#TextTween"&gt;TextTween&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#TextTweenConstructor"&gt;Constructor&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://jstween.sourceforge.net/TextTween_.html" target="_new"&gt;Example&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;a href="#Sequence"&gt;Sequence&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#SequenceMethods"&gt;Methods&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#SequenceEvents"&gt;Events&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#SequenceUsage"&gt;Usage&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://jstween.sourceforge.net/sequence_.html" target="_blank"&gt;Example&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Parallel&lt;/li&gt;&lt;li&gt;&lt;a href="#SeeAction"&gt;See it in action&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#Tween"&gt;&lt;/a&gt;&lt;span style="font-weight:bold;"&gt;The Tween class&lt;/span&gt;&lt;br /&gt;&lt;a name="#TweenConstructor"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;CONSTRUCTOR&lt;/span&gt;&lt;br /&gt;var t = &lt;span style="font-weight:bold;"&gt;new Tween(object,property,easing,start,end,duration,suffixe);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;object:&lt;/span&gt;&lt;br /&gt;type:Object&lt;br /&gt;The object you want to modify.  It can be any object, a visual object that you want to animate ( document.body.style ) or an anymous object ( new Object() ).&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;property:&lt;/span&gt;&lt;br /&gt;type:String&lt;br /&gt;The property that is updated on the target object, it can be empty ('')&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;easing:&lt;/span&gt;&lt;br /&gt;type:Function&lt;br /&gt;The easing that will be applied to motion. ( I have listed the functions below and created a &lt;a href="http://jstween.sourceforge.net/moveSquare.html" target="_new"&gt;sample&lt;/a&gt; to allow you to try them )&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;start:&lt;/span&gt;&lt;br /&gt;type:Number&lt;br /&gt;Start value&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;end:&lt;/span&gt;&lt;br /&gt;type:Number&lt;br /&gt;End value&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;duration:&lt;/span&gt;&lt;br /&gt;type:Number&lt;br /&gt;Animation duration in seconds&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;suffixe:&lt;/span&gt;&lt;br /&gt;type:String&lt;br /&gt;A string to append to the updated property ('%','pt','em' ...). &lt;br /&gt;&lt;a name="#TweenMethods"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;METHODS&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;!--- START() ---&gt;&lt;span style="font-weight:bold;"&gt;start()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- REWIND() ---&gt;&lt;span style="font-weight:bold;"&gt;rewind()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- FFORWARD() ---&gt;&lt;span style="font-weight:bold;"&gt;fforward()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- STOP() ---&gt;&lt;span style="font-weight:bold;"&gt;stop()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- RESUME() ---&gt;&lt;span style="font-weight:bold;"&gt;resume()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- CONTINUETO() ---&gt;&lt;span style="font-weight:bold;"&gt;continueTo( end, duration )&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- YOYO() ---&gt;&lt;span style="font-weight:bold;"&gt;yoyo()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- ADDLISTENER() ---&gt;&lt;span style="font-weight:bold;"&gt;addListener( listenerObject )&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- REMOVELISTENER() ---&gt;&lt;span style="font-weight:bold;"&gt;removeListener( listenerObject )&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a name="#TweenMethodsEx"&gt;&lt;/a&gt;&lt;div style="padding:5px;border:1px dotted #363636"&gt;&lt;br /&gt;&lt;div id="sq" style="width:50px;height:50px;position:relative;left:0px;border:1px solid #333333;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;input type="button" onclick="t1 = new Tween(document.getElementById('sq').style,'left',Tween.elasticEaseOut,0,500,4,'px');t1.start();" value="start()"&gt;&lt;input type="button" onclick="t1.stop();" value="stop()"&gt;&lt;input type="button" onclick="t1.resume();" value="resume()"&gt;&lt;input type="button" onclick="t1.rewind();" value="rewind()"&gt;&lt;input type="button" onclick="t1.fforward();" value="fforward()"&gt;&lt;br /&gt;&lt;span style="text-align:left;"&gt;&amp;lt;div id="sq" style="width:50px;height:50px;position:relative;left:0px;border:1px solid #333333;"&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;input type="button" value="start()" onclick="&lt;br /&gt;t1 = new Tween(document.getElementById('sq').style,'left',Tween.elasticEaseOut,0,500,4,'px');&lt;br /&gt;t1.start();"&amp;gt;&lt;br /&gt;&amp;lt;input type="button" onclick="t1.stop();" value="stop()"&amp;gt;&lt;br /&gt;&amp;lt;input type="button" onclick="t1.resume();" value="resume()"&amp;gt;&lt;br /&gt;&amp;lt;input type="button" onclick="t1.rewind();" value="rewind()"&amp;gt;&lt;br /&gt;&amp;lt;input type="button" onclick="t1.fforward();" value="fforward()"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;a name="#TweenEasing"&gt;&lt;/a&gt;&lt;!--- EASING FUNCTIONS ---&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;Easing functions&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.macromedia.com/devnet/flash/articles/tweening_04.html" targe="_blank"&gt;About Easing Classes and Methods&lt;/a&gt;&lt;br /&gt;The default easing functions are methods of the Tween.as class.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Tween.regularEaseIn&lt;/li&gt;&lt;li&gt;Tween.regularEaseOut&lt;/li&gt;&lt;li&gt;Tween.regularEaseInOut&lt;/li&gt;&lt;li&gt;Tween.strongEaseIn&lt;/li&gt;&lt;li&gt;Tween.strongEaseOut&lt;/li&gt;&lt;li&gt;Tween.strongEaseInOut&lt;/li&gt;&lt;li&gt;Tween.backEaseOut&lt;/li&gt;&lt;li&gt;Tween.backEaseIn&lt;/li&gt;&lt;li&gt;Tween.backEaseInOut&lt;/li&gt;&lt;li&gt;Tween.bounceEaseOut&lt;/li&gt;&lt;li&gt;Tween.bounceEaseIn&lt;/li&gt;&lt;li&gt;Tween.bounceEaseInOut&lt;/li&gt;&lt;li&gt;Tween.elasticEaseIn&lt;/li&gt;&lt;li&gt;Tween.elasticEaseOut&lt;/li&gt;&lt;li&gt;Tween.elasticEaseInOut&lt;/li&gt;&lt;/ul&gt;&lt;a href="http://jstween.sourceforge.net/moveSquare.html" target="_blank"&gt;A sample to try these methods&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#TweenEvents"&gt;&lt;/a&gt;&lt;!--- EVENTS ---&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;EVENTS AND LISTENERS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionStarted( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionChanged( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionFinished( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionStopped( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionLooped( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionResumed( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;the eventObject passed contains 2 properties:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;target : the Tween instance (object)&lt;/li&gt;&lt;li&gt;type : the event name (string, ex: 'onMotionChanged')&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#TweenEventListeners"&gt;&lt;/a&gt;&lt;span style="font-weight:bold;"&gt;2 ways&lt;/span&gt; to use events :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;1Щ&lt;/span&gt; adding a method on your Tween instance with the same name as the event you want to listen.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;t1A = new Tween(document.getElementById('sqA').style,'left',Tween.elasticEaseOut,0,500,1,'px');&lt;br /&gt;&lt;b&gt;t1A.onMotionFinished = function()&lt;/b&gt;{alert( 'onMotionFinished' )};&lt;br /&gt;t1A.start();&lt;br /&gt;&lt;div id="sqA" style="width:50px;height:50px;position:relative;left:0px;border:1px solid #333333;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;input type="button" onclick="t1A = new Tween(document.getElementById('sqA').style,'left',Tween.elasticEaseOut,0,500,1,'px');t1A.onMotionFinished = function(){alert('onMotionFinished ')};t1A.start();" value="start()"&gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;using the yoyo() method, the following code will create an endless animation:&lt;br /&gt;t1C = new Tween(document.getElementById('sqC').style,'left',Tween.elasticEaseOut,0,500,1,'px');&lt;br /&gt;t1C.onMotionFinished = function(){&lt;b&gt;this.yoyo()&lt;/b&gt;};&lt;br /&gt;t1C.start();&lt;br /&gt;&lt;div id="sqC" style="width:50px;height:50px;position:relative;left:0px;border:1px solid #333333;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;input type="button" onclick="t1C = new Tween(document.getElementById('sqC').style,'left',Tween.elasticEaseOut,0,500,1,'px');t1C.onMotionFinished = function(){this.yoyo()};t1C.start();" value="start()"&gt;&lt;br /&gt;&lt;br /&gt;If, for example you wanted the yoyo() to perform only once, you would write code like&lt;br /&gt;t1C.onMotionFinished = function(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.yoyo();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.onMotionFinished = undefined;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;2Щ&lt;/span&gt; using the &lt;span style="font-weight:bold;"&gt;addListener&lt;/span&gt; method:&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;t1A = new Tween(document.getElementById('sqA').style,'left',Tween.elasticEaseOut,0,500,1,'px');&lt;br /&gt;&lt;b&gt;var a = new Object();&lt;/b&gt;&lt;br /&gt;&lt;b&gt;a.onMotionFinished = function()&lt;/b&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;alert( 'onMotionFinished' )&lt;br /&gt;};&lt;br /&gt;&lt;b&gt;a.onMotionStarted = function()&lt;/b&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;alert( 'onMotionStarted' )&lt;br /&gt;}&lt;br /&gt;&lt;b&gt;t1A.addListener(a)&lt;/b&gt;&lt;br /&gt;t1A.start();&lt;br /&gt;&lt;br /&gt;&lt;div id="sqB" style="width:50px;height:50px;position:relative;left:0px;border:1px solid #333333;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;input type="button" onclick="t1B = new Tween(document.getElementById('sqB').style,'left',Tween.elasticEaseOut,0,500,1,'px');var a = new Object();a.onMotionFinished = function(){alert('onMotionFinished ')};a.onMotionStarted = function(){alert('onMotionStarted')};t1B.addListener(a);t1B.start();" value="start()"&gt;&lt;br /&gt;&lt;br /&gt;The advantage of this is that you can add as many listeners as desired.&lt;br /&gt;If you want to remove a listener, you can use the method 'removeListener( listenerObject )', where the listenerObject is the reference to the object that was added as listener.&lt;br /&gt;&lt;br /&gt;Because we are tweening values, it is possible to instantiate a tween that won't directly apply changes to a visual object. &lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;[textarea id="myTA" cols="40" rows="10"][/textarea]&lt;br /&gt;&lt;br /&gt;[input type="button" value="tween from 1 to 100" onClick="&lt;br /&gt;tweenTA = new Tween(&lt;span style="font-weight:bold;"&gt;new Object(),'xyz'&lt;/span&gt;,Tween.bounceEaseOut,1,100,1);&lt;br /&gt;var myTA = document.getElementById('myTA');&lt;br /&gt;myTA.value='';&lt;br /&gt;tweenTA.onMotionChanged = function(event){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;myTA.value += &lt;span style="font-weight:bold;"&gt;event.target._pos&lt;/span&gt; + '\n';&lt;br /&gt;};&lt;br /&gt;tweenTA.start();"]&lt;br /&gt;&lt;br /&gt;&lt;textarea id="myTA" cols="40" rows="10"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;input type="button" value="tween from 1 to 100" onClick="tweenTA = new Tween({xyz:''},'xyz',Tween.bounceEaseOut,1,100,1);var myTA = document.getElementById('myTA');myTA.value='';tweenTA.onMotionChanged = function(event){myTA.value += event.target._pos + '\n';};tweenTA.start();"&gt;&lt;br /&gt;&lt;br /&gt;Same example, but more 'creative':&lt;br /&gt;&lt;br /&gt;[textarea id="myTA2" cols="40" rows="8"][/textarea]&lt;br /&gt;&lt;br /&gt;[input type="button" value="tween text" onClick="&lt;br /&gt;myText='Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';&lt;br /&gt;tweenTA2 = new Tween(new Object(),'xyz',Tween.bounceEaseOut,0,myText.length,3);&lt;br /&gt;var myTA2 = document.getElementById('myTA2');&lt;br /&gt;myTA2.value='';&lt;br /&gt;tweenTA2.onMotionChanged = function(event){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;myTA2.value = myText.substr(0,event.target._pos);&lt;br /&gt;};&lt;br /&gt;tweenTA2.start();"]&lt;br /&gt;&lt;br /&gt;&lt;textarea id="myTA2" cols="40" rows="8"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;input type="button" value="tween text" onClick="myText='Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';tweenTA2 = new Tween(new Object(),'xyz',Tween.bounceEaseOut,0,myText.length,3);var myTA2 = document.getElementById('myTA2');myTA2.value='';tweenTA2.onMotionChanged = function(event){myTA2.value = myText.substr(0,event.target._pos);};tweenTA2.start();"&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#ColorTween"&gt;&lt;/a&gt;&lt;span style="font-weight:bold;"&gt;The ColorTween class&lt;/span&gt;&lt;br /&gt;ColorTween.js extends the Tween.js class, its purpose is to manage transitions between two colors.&lt;br /&gt;Because it is a subclass of Tween you must include the Tween.as class &lt;span style="font-weight:bold;"&gt;before&lt;/span&gt; you include the ColorTween.js class.&lt;br /&gt;&lt;br /&gt;[script language="javascript" src="Tween.js"][/script]&lt;br /&gt;[script language="javascript" src="ColorTween.js"][/script]&lt;br /&gt;&lt;br /&gt;Because ColorTween.js is a subclass of Tween.js, all the Tween methods and events are available.&lt;br /&gt;&lt;br /&gt;&lt;a name="#ColorTweenConstructor"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;CONSTRUCTOR&lt;/span&gt;&lt;br /&gt;var colorTween = &lt;span style="font-weight:bold;"&gt;new ColorTween(object,property,easing,startColor,endColor,duration);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#ColorTweenEx"&gt;&lt;/a&gt;An example will be worth a thousand words:&lt;br /&gt;&lt;br /&gt;[div id="square22" style="width:50px;height:50px;background-color:#FF0000;"][/div]&lt;br /&gt;[input type="button" value="toggle Color (red-blue)" onClick="&lt;br /&gt;colorTween = new ColorTween(document.getElementById('square22').style, 'backgroundColor', Tween.bounceEaseOut, 'FF0000', '0000FF', 3);&lt;br /&gt;colorTween.start()"]&lt;br /&gt;&lt;br /&gt;&lt;div id="square22" style="width:50px;height:50px;background-color:#FF0000;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type="button" value="toggle Color (red-blue)" onClick="colorTween = new ColorTween(document.getElementById('square22').style,'backgroundColor',Tween.bounceEaseOut,'FF0000','0000FF',3);colorTween.start()"&gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;[input type="button" value="Click to animate the background color of this page" onclick="&lt;br /&gt;bgTween = new ColorTween(document.body.style, 'backgroundColor', Tween.bounceEaseOut,'FFFFFF','000000',2);&lt;br /&gt;bgTween.onMotionFinished = function(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.yoyo();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.onMotionFinished = undefined;&lt;br /&gt;};&lt;br /&gt;bgTween.start();"]&lt;br /&gt;&lt;br /&gt;&lt;input type="button" value="Click to animate the background color of this page" onclick="bgTween = new ColorTween(document.body.style, 'backgroundColor', Tween.bounceEaseOut,'FFFFFF','000000',3);bgTween.onMotionFinished = function(){this.yoyo();this.onMotionFinished = undefined;};bgTween.start();"&gt;&lt;br /&gt;&lt;br /&gt;Notice the code in bold, without it, the animation would play forever, which would be useful if we wanted to have an element that blinks or pulse.  I'll let your imagination do the job.&lt;br /&gt;&lt;br /&gt;&lt;input type="button" value="Change the body font color" onclick="bgColorTween=new ColorTween(document.body.style,'color',Tween.bounceEaseOut,'333333','FFFFFF',3);bgColorTween.onMotionFinished=function(){this.yoyo();this.onMotionFinished=undefined;};bgColorTween.start();"&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#OpacityTween"&gt;&lt;/a&gt;&lt;span style="font-weight:bold;"&gt;The OpacityTween class&lt;/span&gt;&lt;br /&gt;OpacityTween.js extends the Tween.js class, its purpose is to manage opacity transitions on visual objects.&lt;br /&gt;Because it is a subclass of Tween you must include the Tween.as class &lt;span style="font-weight:bold;"&gt;before&lt;/span&gt; you include the OpacityTween.js class.&lt;br /&gt;&lt;br /&gt;[script language="javascript" src="Tween.js"][/script]&lt;br /&gt;[script language="javascript" src="OpacityTween.js"][/script]&lt;br /&gt;&lt;br /&gt;Because OpacityTween.js is a subclass of Tween.js, all the Tween methods and events are available.&lt;br /&gt;&lt;a name="#OpacityTweenConstructor"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;CONSTRUCTOR&lt;/span&gt;&lt;br /&gt;var opacityTween = &lt;span style="font-weight:bold;"&gt;new OpacityTween(Object,easing,startOpacity,endOpacity,duration);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="OpacityTweenEx"&gt;&lt;/a&gt;Example:&lt;br /&gt;&lt;br /&gt;[div id="square33" style="width:50px;height:50px;background-color:#FF0000;filter:Alpha(opacity=100);"][/div]&lt;br /&gt;[input type="button" value="change Opacity (100 - 0)" onClick="&lt;br /&gt;opacityTween = new OpacityTween(document.getElementById('square33'),Tween.bounceEaseOut, 100, 0, 3);&lt;br /&gt;opacityTween.start()"]&lt;br /&gt;&lt;br /&gt;&lt;div id="square33" style="width:50px;height:50px;background-color:#FF0000;filter:Alpha(opacity=100);"&gt;&lt;/div&gt;&lt;br /&gt;&lt;input type="button" value="change Opacity (100 - 0)" onClick="opacityTween = new OpacityTween(document.getElementById('square33'),Tween.bounceEaseOut, 100, 0, 3);opacityTween.start()"&gt;&lt;br /&gt;&lt;br /&gt;You will notice the use of 'filter:Alpha(opacity=100);' on the square div.  If you don't add this, IE will will throw an error 'filter.alpha is null or not an object'.&lt;br /&gt;&lt;br /&gt;&lt;a name="#TextTween"&gt;&lt;/a&gt;&lt;span style="font-weight:bold;"&gt;The TextTween class&lt;/span&gt;&lt;br /&gt;TextTween.js extends the Tween.js class, its purpose is to manage text effects.&lt;br /&gt;Because it is a subclass of Tween you must include the Tween.as class &lt;span style="font-weight:bold;"&gt;before&lt;/span&gt; you include the TextTween.js class.&lt;br /&gt;&lt;br /&gt;[script language="javascript" src="Tween.js"][/script]&lt;br /&gt;[script language="javascript" src="TextTween.js"][/script]&lt;br /&gt;&lt;br /&gt;Because TextTween.js is a subclass of Tween.js, all the Tween methods and events are available.&lt;br /&gt;&lt;br /&gt;&lt;a name="#TextTweenConstructor"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;CONSTRUCTOR&lt;/span&gt;&lt;br /&gt;var t = &lt;span style="font-weight:bold;"&gt;new TextTween(object,property,text,easing,duration);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Click &lt;a href="http://jstween.sourceforge.net/TextTween_.html" target="_blank"&gt;here&lt;/a&gt; to see it in action.&lt;br /&gt;I have added the interesting code below the example.&lt;br /&gt;&lt;br /&gt;&lt;a name="#Sequence"&gt;&lt;/a&gt;&lt;span style="font-weight:bold;"&gt;The Sequence class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The sequence.js class allows you to chain Tweens, it means that the Tweens that have been added via the 'addChild()' method will be executed in the sequence they have been added.&lt;br /&gt;Besides, a Sequence can be a child of a Sequence, allowing you to build and reuse complex animations.&lt;br /&gt;&lt;br /&gt;&lt;a name="#SequenceMethods"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;METHODS&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;!--- ADDCHILD() ---&gt;&lt;span style="font-weight:bold;"&gt;addChild( Tween )&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- REMOVECHILD() ---&gt;&lt;span style="font-weight:bold;"&gt;removeChild( Tween )&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- START() ---&gt;&lt;span style="font-weight:bold;"&gt;start()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- REWIND() ---&gt;&lt;span style="font-weight:bold;"&gt;rewind()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- FFORWARD() ---&gt;&lt;span style="font-weight:bold;"&gt;fforward()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- STOP() ---&gt;&lt;span style="font-weight:bold;"&gt;stop()&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;!--- RESUME() ---&gt;&lt;span style="font-weight:bold;"&gt;resume()&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#SequenceEvents"&gt;&lt;/a&gt;&lt;span style="font-style:italic;background-color:#ccc;"&gt;EVENTS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionStarted( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionFinished( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionStopped( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionLooped( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;onMotionResumed( eventObject )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="#SequenceUsage"&gt;&lt;/a&gt;Usage:&lt;br /&gt;var my_seq = new Sequence();&lt;br /&gt;my_seq.addChild(new Tween(elem1.style,'width',Tween.bounceEaseOut,25,100,0.5,'px'));&lt;br /&gt;my_seq.addChild(new Tween(elem2.style,'width',Tween.bounceEaseOut,25,100,0.5,'px'));&lt;br /&gt;my_seq.start()&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/sequence_.html" target="_blank"&gt;Open example in a new window&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;!---&lt;span style="font-weight:bold;"&gt;The Parallel class&lt;/span&gt;---&gt;&lt;br /&gt;&lt;br /&gt;http://jstween.sourceforge.net&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Download&lt;/span&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/Tween.js" target="_blank"&gt;Tween.js&lt;/a&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/ColorTween.js" target="_blank"&gt;ColorTween.js&lt;/a&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/OpacityTween.js" target="_blank"&gt;OpacityTween.js&lt;/a&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/TextTween.js" target="_blank"&gt;TextTween.js&lt;/a&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/Sequence.js" target="_blank"&gt;Sequence.js&lt;/a&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/Parallel.js" target="_blank"&gt;Parallel.js&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;a name="SeeAction"&gt;See it in action&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://2210media.com/dock_menu/" target="_blank"&gt;Dock menu @ 2210media.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://jstween.sourceforge.net/textarea.html" target="_blank"&gt;Expandable textarea from Arturo Monterroso&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;PS: I would be glad to add other examples here, so if you did something with the tween class, do not hesitate to let me know (pim.man at gmail dot com)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;References&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the description of Flash's Tween class:&lt;br /&gt; &lt;br /&gt;&lt;span style="font-style:italic;"&gt;"The Tween class lets you use ActionScript to move, resize, and fade movie clips easily on the Stage by specifying a property of the target movie clip to be tween animated over a number of frames or seconds. The Tween class also lets you specify a variety of easing methods. Easing refers to gradual acceleration or deceleration during an animation, which helps your animations appear more realistic. For example, the options on a drop-down list component you create might gradually increase their speed near the beginning of an animation as the options appear, but slow down before the options come to a full stop at the end of the animation as the list is extended. Flash provides many easing methods that contain equations for this acceleration and deceleration, which change the easing animation accordingly.&lt;br /&gt;&lt;br /&gt;The Tween class also invokes event handlers so your code may respond when an animation starts, stops, or resumes or increments its tweened property value. For example, you can start a second tweened animation when the first tween invokes its Tween.onMotionStopped event handler, indicating that the first tween has stopped."&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.robertpenner.com/" target="_blank"&gt;Robert Penner&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.macromedia.com/devnet/flash/articles/tweening.html" target="_blank"&gt;Using the Tween and Transition Classes in Flash MX 2004&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.macromedia.com/software/flash/flashpro/"&gt;Macromedia Flash&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/21603807-113840530720686868?l=jstween.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jstween.blogspot.com/feeds/113840530720686868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=21603807&amp;postID=113840530720686868' title='106 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21603807/posts/default/113840530720686868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21603807/posts/default/113840530720686868'/><link rel='alternate' type='text/html' href='http://jstween.blogspot.com/2007/01/javascript-motion-tween.html' title='Javascript Motion Tween'/><author><name>pim Maegerman</name><uri>https://profiles.google.com/102069174973969560746</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-rQRPm8io5bc/AAAAAAAAAAI/AAAAAAAAd00/MVQFwwqm3OQ/s512-c/photo.jpg'/></author><thr:total>106</thr:total></entry></feed>
