YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
This demonstrates how to use the YUI Animation to animate the motion of an HTMLElement. Click the button to begin the demo.
The YUI Animation Utility allows you to animate the motion of an HTMLElement.
For this example, we will animate the position of a <div>
element named demo
. Note that you could accomplish this with a positioned element by animating offset properties ("top", "left", etc.), but those values are not necessarily in page coordinates. The points
attribute, introduced in the YAHOO.util.Motion
subclass, ensures that position is always relative to the document (unless using by
rather than to
, which is relative to the current position).
Add a little style so that we can see the animation in action:
Create the demo
element and a button to run the animation:
Now we create an instance of YAHOO.util.Motion
, passing it the element we wish to animate, and the points attribute (an array of [x, y] positions), with the point we are animating to:
The final step is to call the animate
method on our instance to start the animation. The button will be the trigger that begins the animation sequence:
This is an example of animating the motion HTMLElement.
onComplete
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.
Copyright © 2013 Yahoo! Inc. All rights reserved.