6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"><div class="intro">
23
<p>The Anim Utility provides the ability to animate changes to style properties. Advanced easing equations are provided for more interesting animated effects.</p>
24
<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>
26
<h2 id="getting-started">Getting Started</h2>
29
To include the source files for Anim and its dependencies, first load
30
the YUI seed file if you haven't already loaded it.
33
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script></pre>
37
Next, create a new YUI instance for your application and populate it with the
38
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
39
YUI will automatically load any dependencies required by the modules you
43
<pre class="code prettyprint">// Create a new YUI instance and populate it with the required modules.
44
YUI().use('anim', function (Y) {
45
// Anim is available and ready for use. Add implementation
46
// code here.
51
For more information on creating YUI instances and on the
52
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
53
documentation for the <a href="../yui/index.html">YUI Global object</a>.
57
<h3 id="instantiating">Creating an Animation Object</h3>
59
<p>Your Animation implementation will consist of one or more instances of the <code>Anim</code>.</p>
60
<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>
62
<pre class="code prettyprint">var myAnim = new Y.Anim({
63
node: '#demo',
71
<p>To begin the actual animation, call the <code>run</code> method on your <code>Anim</code> instance.</p>
73
<pre class="code prettyprint">myAnim.run();</pre>
76
<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>
78
<h2 id="using">Using Animation</h2>
80
<h3 id="attributes">Accessing Animation Attributes</h3>
82
<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>
84
<pre class="code prettyprint">var myAnim = new Y.Anim({
85
node: '#demo',
93
<h3 id="anim-to">Setting a To Value</h3>
94
<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>
96
<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>
98
<pre class="code prettyprint">var myAnim = new Y.Anim({
99
node: '#demo',
101
width: function(node) {
102
return node.get('offsetWidth') / 2;
109
<h3 id="anim-from">Setting a From Value</h3>
111
<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>
113
<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>
115
<pre class="code prettyprint">var myAnim = new Y.Anim({
116
node: '#demo',
119
height: function(node) {
120
return node.get('winHeight');
131
<h3 id="anim-events">Listening for Events<a name="events"></a></h3>
133
<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>
134
<pre class="code prettyprint">var myAnim = new Y.Anim({
135
node: '#demo',
142
myAnim.on('end', function() {
143
myAnim.get('node').addClass('yui-hidden');
154
<div id="sidebar" class="yui3-u">
156
<div id="toc" class="sidebox">
158
<h2 class="no-toc">Table of Contents</h2>
164
<a href="#getting-started">Getting Started</a>
167
<a href="#instantiating">Creating an Animation Object</a>
172
<a href="#using">Using Animation</a>
175
<a href="#attributes">Accessing Animation Attributes</a>
178
<a href="#anim-to">Setting a To Value</a>
181
<a href="#anim-from">Setting a From Value</a>
184
<a href="#anim-events">Listening for Events<a name="events"></a></a>
194
<div class="sidebox">
196
<h2 class="no-toc">Examples</h2>
200
<ul class="examples">
203
<li data-description="Creating and using a simple animation.">
204
<a href="basic.html">Basic Animation</a>
209
<li data-description="The Animation Utility allows you to implement 'easing effects' — for example, when an animation gradually slows down as it nears completion, that's an easing effect known as 'ease-in'. This example shows you how to use easing effects with your animations.">
210
<a href="easing.html">Easing Effects</a>
215
<li data-description="Color animations can be effective indicators of state during the lifespan of a dynamic page. This example shows you how to animate color attributes of an element.">
216
<a href="colors.html">Animating Colors</a>
221
<li data-description="The direction attribute can be used to reverse the animation on alternate iterations.">
222
<a href="alt-iterations.html">Alternating Iterations</a>
227
<li data-description="This example shows you how to animate the xy coordinates of an element.">
228
<a href="anim-xy.html">Animating XY Position</a>
233
<li data-description="This example demonstrates animating an element along a curved path using bezier control points.">
234
<a href="curve.html">Animating Along a Curved Path</a>
239
<li data-description="The reverse attribute allows you to change the run direction of an animation.">
240
<a href="reverse.html">Reversing an Animation</a>
245
<li data-description="This example demonstrates how to use the end event.">
246
<a href="end-event.html">Using the End Event</a>
262
<div class="sidebox">
264
<h2 class="no-toc">Examples That Use This Component</h2>
268
<ul class="examples">
287
<li data-description="Shows how to create a simple plugin to animate the Overlay's movement and visibility.">
288
<a href="../overlay/overlay-anim-plugin.html">Animation Plugin</a>
293
<li data-description="Working with multiple YUI instances.">
294
<a href="../yui/yui-multi.html">Multiple Instances</a>
299
<li data-description="How to make an animated node a Drop target.">
300
<a href="../dd/anim-drop.html">Animated Drop Targets</a>
312
<script src="../assets/vendor/prettify/prettify-min.js"></script>
313
<script>prettyPrint();</script>