Yahoo! Developer Network Home - Help

Site Search (YDN & YUIBlog):

# YUI Library Examples: Animation Utility: Animating Multiple Attributes

# Animation Utility: Animating Multiple Attributes

This demonstrates how to animate multiple attributes of an HTMLElement using the YUI Animation Utility. Click the button to begin the demo.

View example in new window.

Demo

## Animating Multiple Attributes

The YUI Animation Utility allows you to animate multiple attributes with a single animation instance.

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

Add a little style so that we can see the animation in action:

<style type="text/css"> #demo { background:#ccc; height:300px; width:300px; } </style>

Create the `demo` element and a button to run the animation:

<div id="demo">Demo</div> <button id="demo-run">run</button>

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:

<script type="text/javascript"> var attributes = { height: { to: 100 }, width: { to: 100 } }; var anim = new YAHOO.util.Anim('demo', attributes); </script>

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:

<script type="text/javascript"> YAHOO.util.Event.on('demo-run', 'click', function() { anim.animate(); }); </script>

This is an example of animating multiple style attributes of an HTMLElement.

### Animation Utility Examples:

- Basic Animation
- Animation Easing
- Animating From a Given Value
- Using Custom Units for an Animation
- Animating Multiple Attributes
- Chaining Animations Using `onComplete`
- Animating Colors
- Animating Motion
- Animating Along a Curved Path
- Animated Scrolling
- Glowing Button (included with examples for Button Control)
- Complex Application (included with examples for Layout Manager (beta))

### More Animation Utility Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2008 Yahoo! Inc. All rights reserved.

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