3 Applies visual transitions to any element. Contains Fx.Base, Fx.Style and Fx.Styles
6 <Moo.js>, <Function.js>, <Array.js>, <String.js>, <Element.js>
9 Valerio Proietti, <http://mad4milk.net>
19 Base class for the Mootools fx library.
22 onStart - the function to execute as the effect begins; nothing (<Class.empty>) by default.
23 onComplete - the function to execute after the effect has processed; nothing (<Class.empty>) by default.
24 transition - the equation to use for the effect see <Fx.Transitions>; default is <Fx.Transitions.sineInOut>
25 duration - the duration of the effect in ms; 500 is the default.
26 unit - the unit is 'px' by default (other values include things like 'em' for fonts or '%').
27 wait - boolean: to wait or not to wait for a current transition to end before running another of the same instance. defaults to true.
28 fps - the frames per second for the transition; default is 30
33 setOptions: function(options){
34 this.options = Object.extend({
36 onComplete: Class.empty,
37 transition: Fx.Transitions.sineInOut,
46 var time = new Date().getTime();
47 if (time < this.time + this.options.duration){
48 this.cTime = time - this.time;
51 this.options.onComplete.pass(this.element, this).delay(10);
61 Immediately sets the value with no transition.
64 to - the point to jump to
67 >var myFx = new Fx.Style('myElement', 'opacity').set(0); //will make it immediately transparent
77 this.now = this.compute(this.from, this.to);
80 compute: function(from, to){
81 return this.options.transition(this.cTime, from, (to - from), this.options.duration);
86 Executes an effect from one position to the other.
89 from - integer: staring value
90 to - integer: the ending value
93 >var myFx = new Fx.Style('myElement', 'opacity').custom(0,1); //display a transition from transparent to opaque.
96 custom: function(from, to){
97 if (!this.options.wait) this.clearTimer();
98 if (this.timer) return;
99 this.options.onStart.pass(this.element, this).delay(10);
102 this.time = new Date().getTime();
103 this.timer = this.step.periodical(Math.round(1000/this.options.fps), this);
109 Stops processing the transition.
111 clearTimer: function(){
112 this.timer = $clear(this.timer);
116 setStyle: function(element, property, value){
117 element.setStyle(property, value + this.options.unit);
122 Fx.Base.implement(new Chain);
126 The Style effect; Extends <Fx.Base>, inherits all its properties. Used to transition any css property from one value to another.
129 el - the $(element) to apply the style transition to
130 property - the property to transition
131 options - the Fx.Base options (see: <Fx.Base>)
134 >var marginChange = new fx.Style('myElement', 'margin-top', {duration:500});
135 >marginChange.custom(10, 100);
138 Fx.Style = Fx.Base.extend({
140 initialize: function(el, property, options){
141 this.element = $(el);
142 this.setOptions(options);
143 this.property = property.camelCase();
148 Same as <Fx.Base.set>(0)
157 will apply <Fx.Base.custom>, setting the starting point to the current position.
160 val - the ending value
164 return this.custom(this.now || 0, val);
167 increase: function(){
168 this.setStyle(this.element, this.property, this.now);
175 Allows you to animate multiple css properties at once; Extends <Fx.Base>, inherits all its properties.
178 el - the $(element) to apply the styles transition to
179 options - the fx options (see: <Fx.Base>)
182 >var myEffects = new fx.Styles('myElement', {duration: 1000, transition: fx.linear});
184 > 'height': [10, 100],
185 > 'width': [900, 300]
189 Fx.Styles = Fx.Base.extend({
191 initialize: function(el, options){
192 this.element = $(el);
193 this.setOptions(options);
198 for (var p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]);
203 The function you'll actually use to execute a transition.
212 custom: function(objFromTo){
213 if (this.timer && this.options.wait) return;
216 for (var p in objFromTo){
217 from[p] = objFromTo[p][0];
218 to[p] = objFromTo[p][1];
220 return this.parent(from, to);
223 increase: function(){
224 for (var p in this.now) this.setStyle(this.element, p, this.now[p]);
231 Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
238 Applies an <Fx.Style> to the Element; This a shortcut for <Fx.Style>.
241 >var myEffect = $('myElement').effect('height', {duration: 1000, transition: Fx.Transitions.linear});
242 >myEffect.custom(10, 100);
245 effect: function(property, options){
246 return new Fx.Style(this, property, options);
251 Applies an <Fx.Styles> to the Element; This a shortcut for <Fx.Styles>.
254 >var myEffects = $(myElement).effects({duration: 1000, transition: Fx.Transitions.sineInOut});
255 >myEffects.custom({'height': [10, 100], 'width': [900, 300]});
258 effects: function(options){
259 return new Fx.Styles(this, options);
265 Class: Fx.Transitions
266 A collection of transition equations for use with the <Fx> Class.
269 <Fxtransitions.js> for a whole bunch of transitions.
272 Easing Equations, (c) 2003 Robert Penner (http://www.robertpenner.com/easing/), Open Source BSD License.
277 /* Property: linear */
278 linear: function(t, b, c, d){
282 /* Property: sineInOut */
283 sineInOut: function(t, b, c, d){
284 return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;