1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<div class="intro">
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>The Anim Utility provides the ability to animate changes to style properties. Advanced easing equations are provided for more interesting animated effects.</p>
dabbc541c8dccfa60600f6ecd294ea560054b0ddMatt Sweeney <p><strong>NOTE:</strong> Depending on which features are required, you may want to consider using the <a href="../transition/">Transition Utility</a> as an alternative to Anim. The Transition Utility isn't as feature rich as Anim, but it leverages native CSS Transitions when possible, provides a smaller payload, and can be hardware-accelerated.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney</div>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney{{>getting-started}}
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<div>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <h3 id="instantiating">Creating an Animation Object</h3>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>Your Animation implementation will consist of one or more instances of the <code>Anim</code>.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>To create an <code>Anim</code> instance on your page, pass it a configuration object including the <code>node</code> or selector query for the node that you wish to animate and a <code>to</code> containing the properties you wish to animate.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeneyvar myAnim = new Y.Anim({
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney node: '#demo',
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney to: {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney width: 0,
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney height: 0
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney }
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney});
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>To begin the actual animation, call the <code>run</code> method on your <code>Anim</code> instance.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt SweeneymyAnim.run();
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>See <a href="../api/module_anim.html">the API documentation for the Anim object</a> for more information about its methods and properties.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <h2 id="using">Using Animation</h2>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <h3 id="attributes">Accessing Animation Attributes</h3>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>In addition to passing a configuration object to the <code>Anim</code> constructor, you can access the attributes of your <code>Anim</code> instance via the <code>set</code> and <code>get</code> methods.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeneyvar myAnim = new Y.Anim({
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney node: '#demo',
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney to: {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney width: 0,
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney height: 0
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney }
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney});
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <h3 id="anim-to">Setting a To Value</h3>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>A <code>node</code> attribute and a <code>to</code> attribute containing one or more properties to animate are the minimum requirements for running an animation.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>The value of a <code>to</code> can optionally be a function. If a function is used, it receives the <code>node</code> as its only argument. The return value of the function becomes the <code>to</code> value for that <code>run</code> of the animation.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeneyvar myAnim = new Y.Anim({
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney node: '#demo',
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney to: {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney width: function(node) {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney return node.get('offsetWidth') / 2;
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney },
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney height: 0
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney }
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney});
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <h3 id="anim-from">Setting a From Value</h3>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>Use the optional <code>from</code> attribute to start the animation from a specific value. When <code>from</code> is omitted, the current value is used.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>Like the <code>to</code> attribute, the value of a <code>from</code> property can optionally be a function. If a function is used, it receives the <code>node</code> as its only argument. The return value of the function becomes the <code>from</code> value for that <code>run</code> of the animation.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeneyvar myAnim = new Y.Anim({
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney node: '#demo',
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney from: {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney width: 0,
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney height: function(node) {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney return node.get('winHeight');
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney }
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney },
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney to: {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney width: 0,
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney height: 0
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney }
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney});
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <h3 id="anim-events">Listening for Events<a name="events"></a></h3>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <p>The Animation Utility defines events useful for hooking into the various stages of an animation. The <code>on</code> method is used to attach event listeners.</p>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeneyvar myAnim = new Y.Anim({
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney node: '#demo',
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney to: {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney width: 0,
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney height: 0
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney }
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney});
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt SweeneymyAnim.on('end', function() {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney myAnim.get('node').addClass('yui-hidden');
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney});
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney```
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney</div>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney