Class YAHOO.util.Anim

Object
   |
   +--YAHOO.util.Anim
Direct Known Subclasses:
YAHOO.util.Motion, YAHOO.util.Scroll

class YAHOO.util.Anim
Requires:
YAHOO.util.AnimMgr
YAHOO.util.Easing
YAHOO.util.Dom
YAHOO.util.Event

Base animation class that provides the interface for building animated effects.

Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);

Field Summary [top]

Object attributes
The collection of attributes to be animated. 
Int currentFrame
The location of the current animation on the timeline. 
String defaultUnit
The default unit to use for all attributes if not defined per attribute. 
Object defaultUnits
Per attribute units that should be used by default. 
Number duration
The length of the animation. 
Function method
The method that will provide values to the attribute(s) during the animation. 
Object onComplete
Custom event that fires when animation ends. 
Object onStart
Custom event that fires when animation begins. 
Object onTween
Custom event that fires between each frame. 
Int totalFrames
The total number of frames to be executed. 
Boolean useSeconds
Whether or not the duration should be treated as seconds. 

Constructor Summary [top]

YAHOO.util.Anim
Base class for animated DOM objects. 

Method Summary [top]

void animate ()
Starts the animation by registering it with the animation manager. 
Number doMethod (<String> attribute, <Number> start, <Number> end)
Returns the value computed by the animation's "method". 
Number getAttribute (<String> attribute)
Returns current value of the attribute. 
Object getDefault (<String> attribute)
Returns the default value for the given attribute. 
HTMLElement getEl ()
Returns a reference to the animated element. 
Date getStartTime ()
Returns the animation start time. 
void init (el, <Object> attributes, <Number> duration, <Function> method)
 
Boolean isAnimated ()
Checks whether the element is currently animated. 
void setAttribute (<String> attribute, <Number> val, <String> unit)
Applies a value to an attribute 
void setDefault (<String> attribute, <Number> val)
Sets the default value to be used when "from" is not supplied. 
void stop ()
Stops the animation. 

Field Detail [top]

attributes

Object   attributes
The collection of attributes to be animated.

Example: this.attributes.width = { from: 10, to: 100 }

Each attribute must have at least a "to" or "by" defined in order to animate.

If "to" is supplied, the animation will end with the attribute at that value.

If "by" is supplied, the animation will end at that value plus its starting value.

If both are supplied, "to" is used, and "by" is ignored.

Optional additional member include "from" (the value the attribute should start animating from, defaults to current value), and "unit" (the units to apply to the values).

currentFrame

Int   currentFrame
The location of the current animation on the timeline. In time-based animations, this is used by AnimMgr to ensure the animation finishes on time.

defaultUnit

String   defaultUnit
The default unit to use for all attributes if not defined per attribute.

defaultUnits

Object   defaultUnits
Per attribute units that should be used by default.

duration

Number   duration
The length of the animation. Defaults to "1" (second).

method

Function   method
The method that will provide values to the attribute(s) during the animation. Defaults to "YAHOO.util.Easing.easeNone".

onComplete

Object   onComplete
Custom event that fires when animation ends. Listen via "subscribe" method. DO NOT OVERRIDE (please)

onStart

Object   onStart
Custom event that fires when animation begins. Listen via "subscribe" method. DO NOT OVERRIDE (please)

onTween

Object   onTween
Custom event that fires between each frame. Listen via "subscribe" method. DO NOT OVERRIDE (please)

totalFrames

Int   totalFrames
The total number of frames to be executed. In time-based animations, this is used by AnimMgr to ensure the animation finishes on time.

useSeconds

Boolean   useSeconds
Whether or not the duration should be treated as seconds. Defaults to true.

Constructor Detail [top]

YAHOO.util.Anim

YAHOO.util.Anim (el, <Object> attributes, <Number> duration, <Function> method)
Base class for animated DOM objects.
Parameters:
attributes - The attribute(s) to be animated. Each attribute is an object with at minimum a "to" or "by" member defined. Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). All attribute names use camelCase.
duration - (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based
method - (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method)
HTMLElement - | String} el Reference to the element that will be animated

Method Detail [top]

animate

void animate ()
Starts the animation by registering it with the animation manager.

doMethod

Number doMethod (<String> attribute, <Number> start, <Number> end)
Returns the value computed by the animation's "method".
Parameters:
attribute - The name of the attribute.
start - The value this attribute should start from for this animation.
end - The value this attribute should end at for this animation.
Returns:
The Value to be applied to the attribute.

getAttribute

Number getAttribute (<String> attribute)
Returns current value of the attribute.
Parameters:
attribute - The name of the attribute.
Returns:
val The current value of the attribute.

getDefault

Object getDefault (<String> attribute)
Returns the default value for the given attribute.
Parameters:
attribute - The attribute whose value will be returned.

getEl

HTMLElement getEl ()
Returns a reference to the animated element.

getStartTime

Date getStartTime ()
Returns the animation start time.
Returns:
current value of startTime.

init

void init (el, <Object> attributes, <Number> duration, <Function> method)
Parameters:
attributes - The attribute(s) to be animated. Each attribute is an object with at minimum a "to" or "by" member defined. Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). All attribute names use camelCase.
duration - (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based
method - (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method)
HTMLElement - | String} el Reference to the element that will be animated

isAnimated

Boolean isAnimated ()
Checks whether the element is currently animated.
Returns:
current value of isAnimated.

setAttribute

void setAttribute (<String> attribute, <Number> val, <String> unit)
Applies a value to an attribute
Parameters:
attribute - The name of the attribute.
val - The value to be applied to the attribute.
unit - The unit ('px', '%', etc.) of the value.

setDefault

void setDefault (<String> attribute, <Number> val)
Sets the default value to be used when "from" is not supplied.
Parameters:
attribute - The attribute being set.
val - The default value to be applied to the attribute.

stop

void stop ()
Stops the animation. Normally called by AnimMgr when animation completes.