Class YAHOO.util.Anim
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);
Public Properties
|
attributes : Object |
Anim |
The collection of attributes to be animated.
Each attribute must have at least a "to" or "by" defined in order to ani... |
|
currentFrame : Int |
Anim |
The location of the current animation on the timeline.
In time-based animations, this is used by AnimMgr to ensure th... |
|
duration : Number |
Anim |
The length of the animation. Defaults to "1" (second). |
|
method : Function |
Anim |
The method that will provide values to the attribute(s) during the animation.
Defaults to "YAHOO.util.Easing.easeNone". |
|
totalFrames : Int |
Anim |
The total number of frames to be executed.
In time-based animations, this is used by AnimMgr to ensure the animation ... |
|
useSeconds : Boolean |
Anim |
Whether or not the duration should be treated as seconds.
Defaults to true. |
Public Methods
|
Anim(String | , Object attributes , Number duration , Function method ) |
Anim |
|
|
animate() : void |
Anim |
Starts the animation by registering it with the animation manager. |
|
doMethod(String attr , Number start , Number end ) : Number |
Anim |
Returns the value computed by the animation's "method". |
|
getAttribute(String attr ) : Number |
Anim |
Returns current value of the attribute. |
|
getDefaultUnit(attr attr ) : String |
Anim |
Returns the unit to use when none is supplied. |
|
getEl() : HTMLElement |
Anim |
Returns a reference to the animated element. |
|
getStartTime() : Date |
Anim |
Returns the animation start time. |
|
init(String | , Object attributes , Number duration , Function method ) : void |
Anim |
Constructor for Anim instance. |
|
isAnimated() : Boolean |
Anim |
Checks whether the element is currently animated. |
|
setAttribute(String attr , Number val , String unit ) : void |
Anim |
Applies a value to an attribute. |
|
stop([Boolean finish ]) : void |
Anim |
Stops the animation. Normally called by AnimMgr when animation completes. |
|
toString() : String |
Anim |
Provides a readable name for the Anim instance. |
Public Events
|
onComplete
: () |
Anim |
Custom event that fires when animation ends
Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) |
|
onStart
: () |
Anim |
Custom event that fires when animation begins
Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) |
|
onTween
: () |
Anim |
Custom event that fires between each frame
Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction) |
Property Details
attributes
public Object attributes
The collection of attributes to be animated.
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).
This property is defined by Anim.
currentFrame
public 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.
This property is defined by Anim.
duration
public Number duration
The length of the animation. Defaults to "1" (second).
This property is defined by Anim.
method
public Function method
The method that will provide values to the attribute(s) during the animation.
Defaults to "YAHOO.util.Easing.easeNone".
This property is defined by Anim.
totalFrames
public 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.
This property is defined by Anim.
useSeconds
public Boolean useSeconds
Whether or not the duration should be treated as seconds.
Defaults to true.
This property is defined by Anim.
Constructor Details
Anim
public function Anim(String |
, Object attributes
, Number duration
, Function method
)
Parameters:
|
: StringHTMLElement} el Reference to the element that will be animated
attributes
: ObjectThe 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
: Number(optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based
method
: Function(optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method)
Method Details
animate
public function animate()
Starts the animation by registering it with the animation manager.
This method is defined by Anim.
doMethod
public function doMethod(String attr
, Number start
, Number end
)
Returns the value computed by the animation's "method".
Parameters:
attr
: StringThe name of the attribute.
start
: NumberThe value this attribute should start from for this animation.
end
: NumberThe value this attribute should end at for this animation.
Returns:
This method is defined by Anim.
getAttribute
public function getAttribute(String attr
)
Returns current value of the attribute.
This method is defined by Anim.
getDefaultUnit
public function getDefaultUnit(attr attr
)
Returns the unit to use when none is supplied.
This method is defined by Anim.
getEl
public function getEl()
Returns a reference to the animated element.
This method is defined by Anim.
getStartTime
public function getStartTime()
Returns the animation start time.
This method is defined by Anim.
init
public function init(String |
, Object attributes
, Number duration
, Function method
)
Constructor for Anim instance.
Parameters:
|
: StringHTMLElement} el Reference to the element that will be animated
attributes
: ObjectThe 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
: Number(optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based
method
: Function(optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method)
Returns:
This method is defined by Anim.
isAnimated
public function isAnimated()
Checks whether the element is currently animated.
This method is defined by Anim.
setAttribute
public function setAttribute(String attr
, Number val
, String unit
)
Applies a value to an attribute.
Parameters:
attr
: StringThe name of the attribute.
val
: NumberThe value to be applied to the attribute.
unit
: StringThe unit ('px', '%', etc.) of the value.
Returns:
This method is defined by Anim.
stop
public function stop([Boolean finish
])
Stops the animation. Normally called by AnimMgr when animation completes.
This method is defined by Anim.
toString
public function toString()
Provides a readable name for the Anim instance.
This method is defined by Anim.
Event Details
onComplete
public event onComplete
Custom event that fires when animation ends
Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction)
Subscribers will be called with the following parameters:
This event is defined by Anim.
onStart
public event onStart
Custom event that fires when animation begins
Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction)
Subscribers will be called with the following parameters:
This event is defined by Anim.
onTween
public event onTween
Custom event that fires between each frame
Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction)
Subscribers will be called with the following parameters:
This event is defined by Anim.