|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Anim</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Anim</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p>The Anim Utility provides the ability to animate changes to style properties. Advanced easing equations are provided for more interesting animated effects.</p> |
|
|
32 |
<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> |
|
|
33 |
</div> |
|
|
34 |
<h2 id="getting-started">Getting Started</h2> |
|
|
35 |
|
|
|
36 |
<p> |
|
|
37 |
To include the source files for Anim and its dependencies, first load |
|
|
38 |
the YUI seed file if you haven't already loaded it. |
|
|
39 |
</p> |
|
|
40 |
|
|
|
41 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre> |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
<p> |
|
|
45 |
Next, create a new YUI instance for your application and populate it with the |
|
|
46 |
modules you need by specifying them as arguments to the <code>YUI().use()</code> method. |
|
|
47 |
YUI will automatically load any dependencies required by the modules you |
|
|
48 |
specify. |
|
|
49 |
</p> |
|
|
50 |
|
|
|
51 |
<pre class="code prettyprint"><script> |
|
|
52 |
// Create a new YUI instance and populate it with the required modules. |
|
|
53 |
YUI().use('anim', function (Y) { |
|
|
54 |
// Anim is available and ready for use. Add implementation |
|
|
55 |
// code here. |
|
|
56 |
}); |
|
|
57 |
</script></pre> |
|
|
58 |
|
|
|
59 |
|
|
|
60 |
<p> |
|
|
61 |
For more information on creating YUI instances and on the |
|
|
62 |
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the |
|
|
63 |
documentation for the <a href="../yui/index.html">YUI Global Object</a>. |
|
|
64 |
</p> |
|
|
65 |
|
|
|
66 |
<div> |
|
|
67 |
<h3 id="instantiating">Creating an Animation Object</h3> |
|
|
68 |
|
|
|
69 |
<p>Your Animation implementation will consist of one or more instances of the <code>Anim</code>.</p> |
|
|
70 |
<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> |
|
|
71 |
|
|
|
72 |
<pre class="code prettyprint">var myAnim = new Y.Anim({ |
|
|
73 |
node: '#demo', |
|
|
74 |
to: { |
|
|
75 |
width: 0, |
|
|
76 |
height: 0 |
|
|
77 |
} |
|
|
78 |
});</pre> |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
<p>To begin the actual animation, call the <code>run</code> method on your <code>Anim</code> instance.</p> |
|
|
82 |
|
|
|
83 |
<pre class="code prettyprint">myAnim.run();</pre> |
|
|
84 |
|
|
|
85 |
|
|
|
86 |
<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> |
|
|
87 |
|
|
|
88 |
<h2 id="using">Using Animation</h2> |
|
|
89 |
|
|
|
90 |
<h3 id="attributes">Accessing Animation Attributes</h3> |
|
|
91 |
|
|
|
92 |
<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> |
|
|
93 |
|
|
|
94 |
<pre class="code prettyprint">var myAnim = new Y.Anim({ |
|
|
95 |
node: '#demo', |
|
|
96 |
to: { |
|
|
97 |
width: 0, |
|
|
98 |
height: 0 |
|
|
99 |
} |
|
|
100 |
});</pre> |
|
|
101 |
|
|
|
102 |
|
|
|
103 |
<h3 id="anim-to">Setting a To Value</h3> |
|
|
104 |
<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> |
|
|
105 |
|
|
|
106 |
<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> |
|
|
107 |
|
|
|
108 |
<pre class="code prettyprint">var myAnim = new Y.Anim({ |
|
|
109 |
node: '#demo', |
|
|
110 |
to: { |
|
|
111 |
width: function(node) { |
|
|
112 |
return node.get('offsetWidth') / 2; |
|
|
113 |
}, |
|
|
114 |
height: 0 |
|
|
115 |
} |
|
|
116 |
});</pre> |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
<h3 id="anim-from">Setting a From Value</h3> |
|
|
120 |
|
|
|
121 |
<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> |
|
|
122 |
|
|
|
123 |
<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> |
|
|
124 |
|
|
|
125 |
<pre class="code prettyprint">var myAnim = new Y.Anim({ |
|
|
126 |
node: '#demo', |
|
|
127 |
from: { |
|
|
128 |
width: 0, |
|
|
129 |
height: function(node) { |
|
|
130 |
return node.get('winHeight'); |
|
|
131 |
} |
|
|
132 |
}, |
|
|
133 |
|
|
|
134 |
to: { |
|
|
135 |
width: 0, |
|
|
136 |
height: 0 |
|
|
137 |
} |
|
|
138 |
});</pre> |
|
|
139 |
|
|
|
140 |
|
|
|
141 |
<h3 id="anim-events">Listening for Events<a name="events"></a></h3> |
|
|
142 |
|
|
|
143 |
<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> |
|
|
144 |
<pre class="code prettyprint">var myAnim = new Y.Anim({ |
|
|
145 |
node: '#demo', |
|
|
146 |
to: { |
|
|
147 |
width: 0, |
|
|
148 |
height: 0 |
|
|
149 |
} |
|
|
150 |
}); |
|
|
151 |
|
|
|
152 |
myAnim.on('end', function() { |
|
|
153 |
myAnim.get('node').addClass('yui-hidden'); |
|
|
154 |
});</pre> |
|
|
155 |
|
|
|
156 |
</div> |
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
</div> |
|
|
162 |
</div> |
|
|
163 |
</div> |
|
|
164 |
|
|
|
165 |
<div class="yui3-u-1-4"> |
|
|
166 |
<div class="sidebar"> |
|
|
167 |
|
|
|
168 |
<div id="toc" class="sidebox"> |
|
|
169 |
<div class="hd"> |
|
|
170 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
171 |
</div> |
|
|
172 |
|
|
|
173 |
<div class="bd"> |
|
|
174 |
<ul class="toc"> |
|
|
175 |
<li> |
|
|
176 |
<a href="#getting-started">Getting Started</a> |
|
|
177 |
<ul class="toc"> |
|
|
178 |
<li> |
|
|
179 |
<a href="#instantiating">Creating an Animation Object</a> |
|
|
180 |
</li> |
|
|
181 |
</ul> |
|
|
182 |
</li> |
|
|
183 |
<li> |
|
|
184 |
<a href="#using">Using Animation</a> |
|
|
185 |
<ul class="toc"> |
|
|
186 |
<li> |
|
|
187 |
<a href="#attributes">Accessing Animation Attributes</a> |
|
|
188 |
</li> |
|
|
189 |
<li> |
|
|
190 |
<a href="#anim-to">Setting a To Value</a> |
|
|
191 |
</li> |
|
|
192 |
<li> |
|
|
193 |
<a href="#anim-from">Setting a From Value</a> |
|
|
194 |
</li> |
|
|
195 |
<li> |
|
|
196 |
<a href="#anim-events">Listening for Events<a name="events"></a></a> |
|
|
197 |
</li> |
|
|
198 |
</ul> |
|
|
199 |
</li> |
|
|
200 |
</ul> |
|
|
201 |
</div> |
|
|
202 |
</div> |
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
<div class="sidebox"> |
|
|
207 |
<div class="hd"> |
|
|
208 |
<h2 class="no-toc">Examples</h2> |
|
|
209 |
</div> |
|
|
210 |
|
|
|
211 |
<div class="bd"> |
|
|
212 |
<ul class="examples"> |
|
|
213 |
|
|
|
214 |
|
|
|
215 |
<li data-description="Creating and using a simple animation."> |
|
|
216 |
<a href="basic.html">Basic Animation</a> |
|
|
217 |
</li> |
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
<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."> |
|
|
222 |
<a href="easing.html">Easing Effects</a> |
|
|
223 |
</li> |
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
<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."> |
|
|
228 |
<a href="colors.html">Animating Colors</a> |
|
|
229 |
</li> |
|
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
<li data-description="The direction attribute can be used to reverse the animation on alternate iterations."> |
|
|
234 |
<a href="alt-iterations.html">Alternating Iterations</a> |
|
|
235 |
</li> |
|
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
<li data-description="This example shows you how to animate the xy coordinates of an element."> |
|
|
240 |
<a href="anim-xy.html">Animating XY Position</a> |
|
|
241 |
</li> |
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
<li data-description="This example demonstrates animating an element along a curved path using bezier control points."> |
|
|
246 |
<a href="curve.html">Animating Along a Curved Path</a> |
|
|
247 |
</li> |
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
<li data-description="The reverse attribute allows you to change the run direction of an animation."> |
|
|
252 |
<a href="reverse.html">Reversing an Animation</a> |
|
|
253 |
</li> |
|
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
<li data-description="This example demonstrates how to use the end event."> |
|
|
258 |
<a href="end-event.html">Using the End Event</a> |
|
|
259 |
</li> |
|
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
</ul> |
|
|
269 |
</div> |
|
|
270 |
</div> |
|
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
<div class="sidebox"> |
|
|
275 |
<div class="hd"> |
|
|
276 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
277 |
</div> |
|
|
278 |
|
|
|
279 |
<div class="bd"> |
|
|
280 |
<ul class="examples"> |
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
<li data-description="Working with multiple YUI instances."> |
|
|
300 |
<a href="../yui/yui-multi.html">Multiple Instances</a> |
|
|
301 |
</li> |
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
<li data-description="Shows how to create a simple plugin to animate the Overlay's movement and visibility."> |
|
|
306 |
<a href="../overlay/overlay-anim-plugin.html">Animation Plugin</a> |
|
|
307 |
</li> |
|
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
<li data-description="How to make an animated node a Drop target."> |
|
|
312 |
<a href="../dd/anim-drop.html">Animated Drop Targets</a> |
|
|
313 |
</li> |
|
|
314 |
|
|
|
315 |
|
|
|
316 |
</ul> |
|
|
317 |
</div> |
|
|
318 |
</div> |
|
|
319 |
|
|
|
320 |
</div> |
|
|
321 |
</div> |
|
|
322 |
</div> |
|
|
323 |
</div> |
|
|
324 |
|
|
|
325 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
326 |
<script>prettyPrint();</script> |
|
|
327 |
|
|
|
328 |
<script> |
|
|
329 |
YUI.Env.Tests = { |
|
|
330 |
examples: [], |
|
|
331 |
project: '../assets', |
|
|
332 |
assets: '../assets/anim', |
|
|
333 |
name: 'anim', |
|
|
334 |
title: 'Anim', |
|
|
335 |
newWindow: '', |
|
|
336 |
auto: false |
|
|
337 |
}; |
|
|
338 |
YUI.Env.Tests.examples.push('basic'); |
|
|
339 |
YUI.Env.Tests.examples.push('easing'); |
|
|
340 |
YUI.Env.Tests.examples.push('colors'); |
|
|
341 |
YUI.Env.Tests.examples.push('alt-iterations'); |
|
|
342 |
YUI.Env.Tests.examples.push('anim-xy'); |
|
|
343 |
YUI.Env.Tests.examples.push('curve'); |
|
|
344 |
YUI.Env.Tests.examples.push('reverse'); |
|
|
345 |
YUI.Env.Tests.examples.push('end-event'); |
|
|
346 |
YUI.Env.Tests.examples.push('yui-multi'); |
|
|
347 |
YUI.Env.Tests.examples.push('overlay-anim-plugin'); |
|
|
348 |
YUI.Env.Tests.examples.push('anim-drop'); |
|
|
349 |
|
|
|
350 |
</script> |
|
|
351 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
</body> |
|
|
356 |
</html> |