|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Basic Animation</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 |
|
|
|
24 |
<h1>Example: Basic Animation</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><link href="../assets/anim/anim.css" rel="stylesheet" type="text/css"> |
|
|
29 |
<div class="intro"> |
|
|
30 |
<p>This demonstrates how to animate the <code>opacity</code> of an element.</p> |
|
|
31 |
<p> Click the X in the header to fade out the element.</p> |
|
|
32 |
</div> |
|
|
33 |
|
|
|
34 |
<div class="example"> |
|
|
35 |
<div id="demo" class="yui3-module"> |
|
|
36 |
<div class="yui3-hd"> |
|
|
37 |
<h3>Basic Animation</h3> |
|
|
38 |
<a href="remove.php?id=#demo" title="fade out element" class="yui3-remove"><em>x</em></a> |
|
|
39 |
</div> |
|
|
40 |
<div class="yui3-bd"> |
|
|
41 |
<p>Click the X in the header to fade out the element.</p> |
|
|
42 |
</div> |
|
|
43 |
</div> |
|
|
44 |
|
|
|
45 |
|
|
|
46 |
<script type="text/javascript"> |
|
|
47 |
YUI().use('anim', function(Y) { |
|
|
48 |
var anim = new Y.Anim({ |
|
|
49 |
node: '#demo', |
|
|
50 |
to: { opacity: 0 } |
|
|
51 |
}); |
|
|
52 |
|
|
|
53 |
var onClick = function(e) { |
|
|
54 |
e.preventDefault(); |
|
|
55 |
anim.run(); |
|
|
56 |
}; |
|
|
57 |
|
|
|
58 |
Y.one('#demo .yui3-remove').on('click', onClick); |
|
|
59 |
|
|
|
60 |
}); |
|
|
61 |
|
|
|
62 |
</script> |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
</div> |
|
|
66 |
|
|
|
67 |
<h2>Setting up the HTML</h2> |
|
|
68 |
<p>First we add some HTML to animate.</p> |
|
|
69 |
|
|
|
70 |
<pre class="code prettyprint"><div id="demo" class="yui3-module"> |
|
|
71 |
<div class="yui3-hd"> |
|
|
72 |
<h3>Basic Animation</h3> |
|
|
73 |
<a href="remove.php?id=#demo" title="fade out element" class="yui3-remove"><em>x</em></a> |
|
|
74 |
</div> |
|
|
75 |
<div class="yui3-bd"> |
|
|
76 |
<p>Click the X in the header to fade out the element.</p> |
|
|
77 |
</div> |
|
|
78 |
</div></pre> |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
<h2>Creating the Anim Instance</h2> |
|
|
82 |
<p>Now we create an instance of <code>Y.Anim</code>, passing it a configuration object that includes the <code>node</code> we wish to animate and the <code>to</code> attribute containing the final properties and their values.</p> |
|
|
83 |
|
|
|
84 |
<pre class="code prettyprint">var anim = new Y.Anim({ |
|
|
85 |
node: '#demo', |
|
|
86 |
to: { opacity: 0 } |
|
|
87 |
});</pre> |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
<h2>Handling the Click Event</h2> |
|
|
91 |
<p>Clicking the toggle control should start the animation, so we'll need to handle that click, including preventing the default action of following the url.</p> |
|
|
92 |
|
|
|
93 |
<pre class="code prettyprint">var onClick = function(e) { |
|
|
94 |
e.preventDefault(); |
|
|
95 |
anim.run(); |
|
|
96 |
};</pre> |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
<h2>Running the Animation</h2> |
|
|
100 |
<p>Finally we add an event listener to run the animation.</p> |
|
|
101 |
<pre class="code prettyprint">Y.one('#demo .yui3-remove').on('click', onClick);</pre> |
|
|
102 |
|
|
|
103 |
|
|
|
104 |
<h2>Complete Example Source</h2> |
|
|
105 |
<pre class="code prettyprint"><div id="demo" class="yui3-module"> |
|
|
106 |
<div class="yui3-hd"> |
|
|
107 |
<h3>Basic Animation</h3> |
|
|
108 |
<a href="remove.php?id=#demo" title="fade out element" class="yui3-remove"><em>x</em></a> |
|
|
109 |
</div> |
|
|
110 |
<div class="yui3-bd"> |
|
|
111 |
<p>Click the X in the header to fade out the element.</p> |
|
|
112 |
</div> |
|
|
113 |
</div> |
|
|
114 |
|
|
|
115 |
|
|
|
116 |
<script type="text/javascript"> |
|
|
117 |
YUI().use('anim', function(Y) { |
|
|
118 |
var anim = new Y.Anim({ |
|
|
119 |
node: '#demo', |
|
|
120 |
to: { opacity: 0 } |
|
|
121 |
}); |
|
|
122 |
|
|
|
123 |
var onClick = function(e) { |
|
|
124 |
e.preventDefault(); |
|
|
125 |
anim.run(); |
|
|
126 |
}; |
|
|
127 |
|
|
|
128 |
Y.one('#demo .yui3-remove').on('click', onClick); |
|
|
129 |
|
|
|
130 |
}); |
|
|
131 |
|
|
|
132 |
</script></pre> |
|
|
133 |
|
|
|
134 |
</div> |
|
|
135 |
</div> |
|
|
136 |
</div> |
|
|
137 |
|
|
|
138 |
<div class="yui3-u-1-4"> |
|
|
139 |
<div class="sidebar"> |
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
<div class="sidebox"> |
|
|
144 |
<div class="hd"> |
|
|
145 |
<h2 class="no-toc">Examples</h2> |
|
|
146 |
</div> |
|
|
147 |
|
|
|
148 |
<div class="bd"> |
|
|
149 |
<ul class="examples"> |
|
|
150 |
|
|
|
151 |
|
|
|
152 |
<li data-description="Creating and using a simple animation."> |
|
|
153 |
<a href="basic.html">Basic Animation</a> |
|
|
154 |
</li> |
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
<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."> |
|
|
159 |
<a href="easing.html">Easing Effects</a> |
|
|
160 |
</li> |
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
<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."> |
|
|
165 |
<a href="colors.html">Animating Colors</a> |
|
|
166 |
</li> |
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
<li data-description="The direction attribute can be used to reverse the animation on alternate iterations."> |
|
|
171 |
<a href="alt-iterations.html">Alternating Iterations</a> |
|
|
172 |
</li> |
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
<li data-description="This example shows you how to animate the xy coordinates of an element."> |
|
|
177 |
<a href="anim-xy.html">Animating XY Position</a> |
|
|
178 |
</li> |
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
<li data-description="This example demonstrates animating an element along a curved path using bezier control points."> |
|
|
183 |
<a href="curve.html">Animating Along a Curved Path</a> |
|
|
184 |
</li> |
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
<li data-description="The reverse attribute allows you to change the run direction of an animation."> |
|
|
189 |
<a href="reverse.html">Reversing an Animation</a> |
|
|
190 |
</li> |
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
<li data-description="This example demonstrates how to use the end event."> |
|
|
195 |
<a href="end-event.html">Using the End Event</a> |
|
|
196 |
</li> |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
</ul> |
|
|
206 |
</div> |
|
|
207 |
</div> |
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
<div class="sidebox"> |
|
|
212 |
<div class="hd"> |
|
|
213 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
214 |
</div> |
|
|
215 |
|
|
|
216 |
<div class="bd"> |
|
|
217 |
<ul class="examples"> |
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
<li data-description="Working with multiple YUI instances."> |
|
|
237 |
<a href="../yui/yui-multi.html">Multiple Instances</a> |
|
|
238 |
</li> |
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
<li data-description="Shows how to create a simple plugin to animate the Overlay's movement and visibility."> |
|
|
243 |
<a href="../overlay/overlay-anim-plugin.html">Animation Plugin</a> |
|
|
244 |
</li> |
|
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
<li data-description="How to make an animated node a Drop target."> |
|
|
249 |
<a href="../dd/anim-drop.html">Animated Drop Targets</a> |
|
|
250 |
</li> |
|
|
251 |
|
|
|
252 |
|
|
|
253 |
</ul> |
|
|
254 |
</div> |
|
|
255 |
</div> |
|
|
256 |
|
|
|
257 |
</div> |
|
|
258 |
</div> |
|
|
259 |
</div> |
|
|
260 |
</div> |
|
|
261 |
|
|
|
262 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
263 |
<script>prettyPrint();</script> |
|
|
264 |
|
|
|
265 |
<script> |
|
|
266 |
YUI.Env.Tests = { |
|
|
267 |
examples: [], |
|
|
268 |
project: '../assets', |
|
|
269 |
assets: '../assets/anim', |
|
|
270 |
name: 'basic', |
|
|
271 |
title: 'Basic Animation', |
|
|
272 |
newWindow: '', |
|
|
273 |
auto: false |
|
|
274 |
}; |
|
|
275 |
YUI.Env.Tests.examples.push('basic'); |
|
|
276 |
YUI.Env.Tests.examples.push('easing'); |
|
|
277 |
YUI.Env.Tests.examples.push('colors'); |
|
|
278 |
YUI.Env.Tests.examples.push('alt-iterations'); |
|
|
279 |
YUI.Env.Tests.examples.push('anim-xy'); |
|
|
280 |
YUI.Env.Tests.examples.push('curve'); |
|
|
281 |
YUI.Env.Tests.examples.push('reverse'); |
|
|
282 |
YUI.Env.Tests.examples.push('end-event'); |
|
|
283 |
YUI.Env.Tests.examples.push('yui-multi'); |
|
|
284 |
YUI.Env.Tests.examples.push('overlay-anim-plugin'); |
|
|
285 |
YUI.Env.Tests.examples.push('anim-drop'); |
|
|
286 |
|
|
|
287 |
</script> |
|
|
288 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
</body> |
|
|
293 |
</html> |