/** * S2.FX.Transitions * * Transitions can fine-tune how an effect evolves over time. All effects, * without the use of transitions, normally evolve linearily. * * All transitions take a `position` argument, which is between * 0 (start of effect) and 1 (end of effect). Transitions return a number, * which is a "translation" of `position` argument. The return value can, * depending on transition type, be above 1 or below 0. * * By using Transitions, it is easily possible to add movement easing, * pulsation, bouncing, reversal and other forms of special effects. * *

Default transition

Implementing your own transitions * * Transitions can easily be added, by using this template: * * Object.extend(S2.FX.Transitions, { * myTransition: function(pos) { * return pos; // do your calculations here! * } * }); * * Transitions defined this way automatically become available to be used with * the shorthand syntax for the `options.transition` argument: * * $('some_element').morph('left:300px', { transition: 'myTransition' }); * *

Notice

* * The equations defined in penner.js are open source under the BSD License. * Easing Equations * © 2003 Robert Penner, * all rights reserved. **/ S2.FX.Transitions = { /** * S2.FX.Transitions.linear(pos) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * * Basic linear transition, no easing or other alteration of the effect. *
**/ linear: Prototype.K, /** * S2.FX.Transitions.sinusoidal(pos) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * * Alters the effect timing to be aligned to a sine wave. *
**/ sinusoidal: function(pos) { return (-Math.cos(pos*Math.PI)/2) + 0.5; }, /** * S2.FX.Transitions.reverse(pos) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * * Effect is executed in a reverse linear fashion. *
**/ reverse: function(pos) { return 1 - pos; }, /** * S2.FX.Transitions.mirror(pos[, transition]) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * - transition (Function): a S2.FX.Transitions transition function * * The given transition is mirrored. Defaults to [[S2.FX.Transitions.sinusoidal]]. *
* * You can use other transitions as per the following code sample: * * $('element_id').morph('font-size:200px', { * transition: function(pos){ * return S2.FX.Transitions.mirror(pos, S2.FX.Transitions.bounce); * } * }); * * If you plan to reuse such a mirrored transition often, define your own transition * function: * * S2.FX.Transitions.mirroredBounce = function(pos){ * return S2.FX.Transitions.mirror(pos, S2.FX.Transitions.bounce); * }); * * $('element_id').morph('font-size:200px', { transition: 'mirroredBounce' }); **/ mirror: function(pos, transition) { transition = transition || S2.FX.Transitions.sinusoidal; if(pos<0.5) return transition(pos*2); else return transition(1-(pos-0.5)*2); }, /** * S2.FX.Transitions.flicker(pos) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * * Effect flickers along a sine wave. *
**/ flicker: function(pos) { var pos = pos + (Math.random()-0.5)/5; return S2.FX.Transitions.sinusoidal(pos < 0 ? 0 : pos > 1 ? 1 : pos); }, /** * S2.FX.Transitions.wobble(pos) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * * Effect wobbles increasingly fast between start and end positions. *
**/ wobble: function(pos) { return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; }, /** * S2.FX.Transitions.pulse(pos[, pulses]) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * - pulses (Number): Number of pulses, defaults to 5 * * Effect pulses along a sinusoidal transition. *
**/ pulse: function(pos, pulses) { return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5; }, /** * S2.FX.Transitions.blink(pos[, blinks]) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * - pulses (Number): Number of blinks, defaults to 5 * * Effect blinks on and off. *
**/ blink: function(pos, blinks) { return Math.round(pos*(blinks||5)) % 2; }, /** * S2.FX.Transitions.spring(pos) -> Number * - pos (Number): position between 0 (start of effect) and 1 (end of effect) * * Alters the effect timing to a "spring". *
**/ spring: function(pos) { return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6)); }, /** * S2.FX.Transitions.none() -> Number * * No transition, the effect stays in intial state (returns 0 regardless of input values). *
**/ none: Prototype.K.curry(0), /** * S2.FX.Transitions.full() -> Number * * No transition, the effect is always in final state (returns 1 regardless of input values). *
**/ full: Prototype.K.curry(1) }; //= require //= require