Scriptaculous Effect.Tween: how it works
Thursday, March 20, 2008Of all the libraries "web 2.0" available, scriptaculous is certainly the most poorly documented! On the official website, often slow, the documentation is incomplete, poorly made and difficult to use. With the latest releases, then, some new features are completely missing, just as the new core effect Tween (Effect.Tween). The latter, similar to the Tween in Flash, allows you to manipulate transitions. SYNOPSIS its base is the following:
- object , from , to ) ; Effect. Tween (object, from, to);
This new effect can thus execute a tween (transition) between two values, call methods or set properties of an object (including the elements of the HTML DOM). It also supports callback functions that will have the context of the object on which you run the transition.
Let's see some examples:
a) Performs a property Tween mp object mo
- { mp : 0 } var mo = (MP: 0)
- / /
- ( mo , 30 , 80 , 'mp' ) ; New Effect. Tween (mo, 30, 80, 'mp');
b) Perform a Tween on the element 'foo' DOM HTML
- "foo" >< / div> <div id = "foo"> </ div>
- 'foo' ', 0, 100, ' innerHTML '); EffectTween new ( 'foo' ', 0, 100,' innerHTML ');
c) Set the standard parameters supported by scriptaculous:
- ( 'foo' , 10 , 100 , { duration : 10 } , 'innerHTML' ) ; New Effect. Tween ( 'foo', 10, 100, (duration: 10), 'innerHTML');
d) Use of callback functions:
- ( 'foo' , 10 , 100 , { duration : 10.0 } , function ( p ) { New Effect. Tween ( 'foo', 10, 100, (duration: 10.0), function (p) (
- = 'Countdown: ' + p this. innerHTML = 'Countdown:' + p
- )
- )
e) type of transition:
- ( 'foo' , 10 , 100 , { duration : 10 , transition : Effect. Transitions . sinoidal } , 'innerHTML' ) ; New Effect. Tween ( 'foo', 10, 100, (duration: 10, transition: Effect. Transitions. sinoidal), 'innerHTML');
f) The standard of the events:
- ( 'foo' , 10 , 100 , { duration : 2 , afterFinish : function ( ) { alert ( "Game Over" ) ; } } , function ( p ) { this . innerHTML = 'Countdown: ' + p } ) ; New Effect. Tween ( 'foo', 10, 100, (duration: 2, afterFinish: function () (alert ( "Game Over");)), function (p) (this. innerHTML = 'Countdown:' + p ));
To test these examples you can use the following complete code:
- DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "text/javascript" src = "js/prototype.js" >< / script> <script "text/javascript" type = src = "js/prototype.js"> </ script>
- "text/javascript" src = "js/scriptaculous.js?load=effects" >< / script> <script "text/javascript" type = src = "js/scriptaculous.js?load=effects"> </ script>
- "text/javascript" > <script type = "text/javascript">
- / /
- Event.observe (window, 'load', main);
- / /
- function main () (
- Effect.Tween new ( 'foo', 10, 100, (duration: 2, afterFinish: function () (alert ( "Game Over");)), function (p) = (this.innerHTML 'Countdown:' + p ));
- )
- "foo" >< / div> <div id = "foo"> </ div>













There are no comments for this post
Leave a comment