This demonstrates how to use YUI Animation with units other than pixels. Click the button to begin the demo.
The YUI Animation Utility allows you to animate style attributes in any CSS unit.
For this example, we will animate the width of the
<div> element named
demo in EM units. Using EMs is nice, because it becomes relative to the text size, and will scale as the user changes the browser text size setting.
Add a little style so that we can see the animation in action:
demo element and a button to run the animation:
Now we create an instance of
YAHOO.util.Anim, passing it the element we wish to animate, and the style attribute(s) to be animated. Because we are changing the unit to something other than the default ("px"), the
from field is required:
The final step is to call the
animate method on our instance to start the animation. To keep things simple, we will animate when the document is clicked:
This is an example of animating in units other than pixels.
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.