YUI Library Home

YUI Library Examples: Animation Utility: Animating From a Given Value

Animation Utility: Animating From a Given Value

This demonstrates how to start a YUI Animation from a given value. Click the button to begin the demo.

Demo

Starting an Animation From a Given Value

The YUI Animation Utility allows you to specify arbitrary starting values for your animations.

For this example, we will animate the width of the <div> element named demo.

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.Anim, passing it the element we wish to animate, and the style attribute(s) to be animated. The from field is optional (will start from current value if omitted). In this case, we will start from 600:

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 customizing the starting animation value with YUI Animation Utility.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings