YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Animation Utility: Animation Easing

# Animation Utility: Animation Easing

This demonstrates how to apply an Easing to a YUI Animation instance. Click the button to begin the demo.

View example in new window.

Demo

## Animation with Easing

The YUI Animation Utility includes an Easing feature, which allows you to customize how the animation behaves.

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:

<style type="text/css"> #demo { background:#ccc; overflow:hidden; /* so we can animate to zero width */ width:200px; } </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. The duration and easing arguments are optional. In this case, we will use 1 second as the duration, and the `easeOut` easing, which will slow the animation gradually as it nears the end:

<script type="text/javascript"> var attributes = { width: { to: 0 } }; var anim = new YAHOO.util.Anim('demo', attributes, 1, YAHOO.util.Easing.easeOut); </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 the Easing feature of the 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.

### 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
- Animating multiple elements with StyleSheet (included with examples for StyleSheet Utility)
- Glowing Button (included with examples for Button Control)
- Complex Application (included with examples for Layout Manager)

### More Animation Utility Resources:

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

Copyright © 2010 Yahoo! Inc. All rights reserved.

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