|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Image Sprite Animation with Dial</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: Image Sprite Animation with Dial</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><div class="intro"> |
|
|
29 |
<p>This example shows how to use a <code>Dial</code> widget to animate an image sprite.</p> |
|
|
30 |
<p>Drag the <code>Dial</code> handle, or use the keyboard arrow keys to see the duck image "animate".</p> |
|
|
31 |
</div> |
|
|
32 |
|
|
|
33 |
<div class="example yui3-skin-sam"> |
|
|
34 |
|
|
|
35 |
<style> |
|
|
36 |
|
|
|
37 |
.example { |
|
|
38 |
background-color: #59554F; |
|
|
39 |
text-align: center; |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
.example .container { |
|
|
43 |
text-align: left; |
|
|
44 |
position: relative; |
|
|
45 |
width: 554px; |
|
|
46 |
margin: 10px auto; |
|
|
47 |
padding: 0; |
|
|
48 |
font-family: georgia; |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
.example #demo { |
|
|
52 |
position: absolute; |
|
|
53 |
top: -10px; |
|
|
54 |
left: 350px; |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
.example #duck { |
|
|
58 |
width:300px; |
|
|
59 |
height:188px; |
|
|
60 |
background:url(../assets/dial/images/sprite_duck.jpg) no-repeat; |
|
|
61 |
background-position: 0 0; |
|
|
62 |
border:solid 1px #958A71; |
|
|
63 |
-moz-box-shadow:7px 7px 10px rgba(0,0,0,0.3); |
|
|
64 |
-webkit-box-shadow:7px 7px 10px rgba(0,0,0,0.3); |
|
|
65 |
-moz-border-radius:3px; |
|
|
66 |
-webkit-border-radius:3px; |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
.example .yui3-dial-label { |
|
|
70 |
visibility:hidden; |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
.example .yui3-dial-north-mark { |
|
|
74 |
visibility:hidden; |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
.example .yui3-skin-sam #demo .yui3-dial-ring { |
|
|
78 |
-moz-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3); |
|
|
79 |
-webkit-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3); |
|
|
80 |
} |
|
|
81 |
|
|
|
82 |
.example #text { |
|
|
83 |
color:#C5B291; |
|
|
84 |
} |
|
|
85 |
|
|
|
86 |
.example #text h2 { |
|
|
87 |
font-size:261%; |
|
|
88 |
color:#EEE5D6; |
|
|
89 |
text-shadow: 2px 2px 7px #000; |
|
|
90 |
margin: 0; |
|
|
91 |
font-family: georgia; |
|
|
92 |
} |
|
|
93 |
|
|
|
94 |
.example #text h3 { |
|
|
95 |
color:#EEE5D6; |
|
|
96 |
font-size: 100%; |
|
|
97 |
margin: 0.6em 0; |
|
|
98 |
font-family: georgia; |
|
|
99 |
} |
|
|
100 |
|
|
|
101 |
.example #text p { |
|
|
102 |
margin: 0.5em 0; |
|
|
103 |
font-size:135%; |
|
|
104 |
line-height: 1.2em; |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
</style> |
|
|
108 |
|
|
|
109 |
|
|
|
110 |
<div class="container"> |
|
|
111 |
<div id="duck"></div> |
|
|
112 |
<div id="demo"></div> |
|
|
113 |
<div id="text"> |
|
|
114 |
<h3>Lot #562</h3> |
|
|
115 |
<h2>Duck Decoy - Thomas Jefferson</h2> |
|
|
116 |
<p> |
|
|
117 |
Hand carved and signed by Thomas Jefferson. |
|
|
118 |
circa 1785. Native hardwoods, stains, pigments. |
|
|
119 |
Glass bead eyes. |
|
|
120 |
</p> |
|
|
121 |
<p> |
|
|
122 |
Opening bid $93,000 |
|
|
123 |
</p> |
|
|
124 |
</div> |
|
|
125 |
</div> |
|
|
126 |
|
|
|
127 |
<script type="text/javascript"> |
|
|
128 |
YUI().use("dial", function(Y) { |
|
|
129 |
var oneFrameWidth = 300, |
|
|
130 |
framesInSprite = 13; |
|
|
131 |
var dial = new Y.Dial({ |
|
|
132 |
min: 0, |
|
|
133 |
max: 26000, |
|
|
134 |
value: 13000, // initial value in the middle of a large range allows rotation both ways |
|
|
135 |
minorStep: 1, |
|
|
136 |
majorStep: 2, |
|
|
137 |
stepsPerRevolution: framesInSprite, |
|
|
138 |
diameter: 150 |
|
|
139 |
}); |
|
|
140 |
dial.render('#demo'); |
|
|
141 |
|
|
|
142 |
// Reposition the duck sprite background image |
|
|
143 |
dial.on( "valueChange", function(e){ |
|
|
144 |
// Handle values greater than one revolution |
|
|
145 |
var moduloValue = (e.newVal % framesInSprite); |
|
|
146 |
|
|
|
147 |
Y.one('#duck').setStyle('backgroundPosition', (moduloValue * -oneFrameWidth) + 'px 0px'); |
|
|
148 |
}, '#duck' ); |
|
|
149 |
}); |
|
|
150 |
</script> |
|
|
151 |
|
|
|
152 |
</div> |
|
|
153 |
|
|
|
154 |
<h3>The Image Sprite</h3> |
|
|
155 |
<p><img src="../assets/dial/images/sprite_duck.jpg" width="676" height="33"/></p> |
|
|
156 |
|
|
|
157 |
<h3>The Markup</h3> |
|
|
158 |
<p>The <code><div id="duck"></div></code> element will have the sprite as its background-image. |
|
|
159 |
<p>The <code><div id="demo"></div></code> element will contain the dial.</p> |
|
|
160 |
<p></p> |
|
|
161 |
<p> |
|
|
162 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
163 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
164 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
165 |
</p> |
|
|
166 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
167 |
|
|
|
168 |
|
|
|
169 |
<pre class="code prettyprint"><div class="container"> |
|
|
170 |
<div id="duck"></div> |
|
|
171 |
<div id="demo"></div> |
|
|
172 |
<div id="text"> |
|
|
173 |
<h3>Lot #562</h3> |
|
|
174 |
<h2>Duck Decoy - Thomas Jefferson</h2> |
|
|
175 |
<p> |
|
|
176 |
Hand carved and signed by Thomas Jefferson. |
|
|
177 |
circa 1785. Native hardwoods, stains, pigments. |
|
|
178 |
Glass bead eyes. |
|
|
179 |
</p> |
|
|
180 |
<p> |
|
|
181 |
Opening bid $93,000 |
|
|
182 |
</p> |
|
|
183 |
</div> |
|
|
184 |
</div></pre> |
|
|
185 |
|
|
|
186 |
<h3>The JavaScript</h3> |
|
|
187 |
<p>The <code>stepsPerRevolution</code> attribute of the <code>Dial</code> |
|
|
188 |
is given a value equal to the number of frames in the sprite. |
|
|
189 |
</p> |
|
|
190 |
<p> |
|
|
191 |
On <code>valueChange</code> of the <code>dial</code>, the <code>background-position</code> of <code><div id="duck"></code> |
|
|
192 |
is changed to a new multiple of the |
|
|
193 |
width of one frame in the sprite. |
|
|
194 |
</p> |
|
|
195 |
<pre class="code prettyprint"><script type="text/javascript"> |
|
|
196 |
YUI().use("dial", function(Y) { |
|
|
197 |
var oneFrameWidth = 300, |
|
|
198 |
framesInSprite = 13; |
|
|
199 |
var dial = new Y.Dial({ |
|
|
200 |
min: 0, |
|
|
201 |
max: 26000, |
|
|
202 |
value: 13000, // initial value in the middle of a large range allows rotation both ways |
|
|
203 |
minorStep: 1, |
|
|
204 |
majorStep: 2, |
|
|
205 |
stepsPerRevolution: framesInSprite, |
|
|
206 |
diameter: 150 |
|
|
207 |
}); |
|
|
208 |
dial.render('#demo'); |
|
|
209 |
|
|
|
210 |
// Reposition the duck sprite background image |
|
|
211 |
dial.on( "valueChange", function(e){ |
|
|
212 |
// Handle values greater than one revolution |
|
|
213 |
var moduloValue = (e.newVal % framesInSprite); |
|
|
214 |
|
|
|
215 |
Y.one('#duck').setStyle('backgroundPosition', (moduloValue * -oneFrameWidth) + 'px 0px'); |
|
|
216 |
}, '#duck' ); |
|
|
217 |
}); |
|
|
218 |
</script></pre> |
|
|
219 |
|
|
|
220 |
<h3>Complete Example Source</h3> |
|
|
221 |
<pre class="code prettyprint"><style> |
|
|
222 |
|
|
|
223 |
.example { |
|
|
224 |
background-color: #59554F; |
|
|
225 |
text-align: center; |
|
|
226 |
} |
|
|
227 |
|
|
|
228 |
.example .container { |
|
|
229 |
text-align: left; |
|
|
230 |
position: relative; |
|
|
231 |
width: 554px; |
|
|
232 |
margin: 10px auto; |
|
|
233 |
padding: 0; |
|
|
234 |
font-family: georgia; |
|
|
235 |
} |
|
|
236 |
|
|
|
237 |
.example #demo { |
|
|
238 |
position: absolute; |
|
|
239 |
top: -10px; |
|
|
240 |
left: 350px; |
|
|
241 |
} |
|
|
242 |
|
|
|
243 |
.example #duck { |
|
|
244 |
width:300px; |
|
|
245 |
height:188px; |
|
|
246 |
background:url(../assets/dial/images/sprite_duck.jpg) no-repeat; |
|
|
247 |
background-position: 0 0; |
|
|
248 |
border:solid 1px #958A71; |
|
|
249 |
-moz-box-shadow:7px 7px 10px rgba(0,0,0,0.3); |
|
|
250 |
-webkit-box-shadow:7px 7px 10px rgba(0,0,0,0.3); |
|
|
251 |
-moz-border-radius:3px; |
|
|
252 |
-webkit-border-radius:3px; |
|
|
253 |
} |
|
|
254 |
|
|
|
255 |
.example .yui3-dial-label { |
|
|
256 |
visibility:hidden; |
|
|
257 |
} |
|
|
258 |
|
|
|
259 |
.example .yui3-dial-north-mark { |
|
|
260 |
visibility:hidden; |
|
|
261 |
} |
|
|
262 |
|
|
|
263 |
.example .yui3-skin-sam #demo .yui3-dial-ring { |
|
|
264 |
-moz-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3); |
|
|
265 |
-webkit-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3); |
|
|
266 |
} |
|
|
267 |
|
|
|
268 |
.example #text { |
|
|
269 |
color:#C5B291; |
|
|
270 |
} |
|
|
271 |
|
|
|
272 |
.example #text h2 { |
|
|
273 |
font-size:261%; |
|
|
274 |
color:#EEE5D6; |
|
|
275 |
text-shadow: 2px 2px 7px #000; |
|
|
276 |
margin: 0; |
|
|
277 |
font-family: georgia; |
|
|
278 |
} |
|
|
279 |
|
|
|
280 |
.example #text h3 { |
|
|
281 |
color:#EEE5D6; |
|
|
282 |
font-size: 100%; |
|
|
283 |
margin: 0.6em 0; |
|
|
284 |
font-family: georgia; |
|
|
285 |
} |
|
|
286 |
|
|
|
287 |
.example #text p { |
|
|
288 |
margin: 0.5em 0; |
|
|
289 |
font-size:135%; |
|
|
290 |
line-height: 1.2em; |
|
|
291 |
} |
|
|
292 |
|
|
|
293 |
</style> |
|
|
294 |
|
|
|
295 |
|
|
|
296 |
<div class="container"> |
|
|
297 |
<div id="duck"></div> |
|
|
298 |
<div id="demo"></div> |
|
|
299 |
<div id="text"> |
|
|
300 |
<h3>Lot #562</h3> |
|
|
301 |
<h2>Duck Decoy - Thomas Jefferson</h2> |
|
|
302 |
<p> |
|
|
303 |
Hand carved and signed by Thomas Jefferson. |
|
|
304 |
circa 1785. Native hardwoods, stains, pigments. |
|
|
305 |
Glass bead eyes. |
|
|
306 |
</p> |
|
|
307 |
<p> |
|
|
308 |
Opening bid $93,000 |
|
|
309 |
</p> |
|
|
310 |
</div> |
|
|
311 |
</div> |
|
|
312 |
|
|
|
313 |
<script type="text/javascript"> |
|
|
314 |
YUI().use("dial", function(Y) { |
|
|
315 |
var oneFrameWidth = 300, |
|
|
316 |
framesInSprite = 13; |
|
|
317 |
var dial = new Y.Dial({ |
|
|
318 |
min: 0, |
|
|
319 |
max: 26000, |
|
|
320 |
value: 13000, // initial value in the middle of a large range allows rotation both ways |
|
|
321 |
minorStep: 1, |
|
|
322 |
majorStep: 2, |
|
|
323 |
stepsPerRevolution: framesInSprite, |
|
|
324 |
diameter: 150 |
|
|
325 |
}); |
|
|
326 |
dial.render('#demo'); |
|
|
327 |
|
|
|
328 |
// Reposition the duck sprite background image |
|
|
329 |
dial.on( "valueChange", function(e){ |
|
|
330 |
// Handle values greater than one revolution |
|
|
331 |
var moduloValue = (e.newVal % framesInSprite); |
|
|
332 |
|
|
|
333 |
Y.one('#duck').setStyle('backgroundPosition', (moduloValue * -oneFrameWidth) + 'px 0px'); |
|
|
334 |
}, '#duck' ); |
|
|
335 |
}); |
|
|
336 |
</script></pre> |
|
|
337 |
|
|
|
338 |
|
|
|
339 |
</div> |
|
|
340 |
</div> |
|
|
341 |
</div> |
|
|
342 |
|
|
|
343 |
<div class="yui3-u-1-4"> |
|
|
344 |
<div class="sidebar"> |
|
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
<div class="sidebox"> |
|
|
349 |
<div class="hd"> |
|
|
350 |
<h2 class="no-toc">Examples</h2> |
|
|
351 |
</div> |
|
|
352 |
|
|
|
353 |
<div class="bd"> |
|
|
354 |
<ul class="examples"> |
|
|
355 |
|
|
|
356 |
|
|
|
357 |
<li data-description="Create a Dial from existing markup on the page - a simple use case."> |
|
|
358 |
<a href="dial-basic.html">Basic Dial</a> |
|
|
359 |
</li> |
|
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
<li data-description="Link a Dial with a text input field."> |
|
|
364 |
<a href="dial-text-input.html">Dial Linked With Text Input</a> |
|
|
365 |
</li> |
|
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
|
369 |
<li data-description="Use image backgrounds to control the visual display of a Dial."> |
|
|
370 |
<a href="dial-image-background.html">Dial With Image Background</a> |
|
|
371 |
</li> |
|
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
<li data-description="Use images to surround a Dial instance and provide additional styling."> |
|
|
376 |
<a href="dial-image-surrounding.html">Dial With a Surrounding Image</a> |
|
|
377 |
</li> |
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
<li data-description="This example employs Dial to drive an interactive UI."> |
|
|
382 |
<a href="dial-interactive.html">Dial With Interactive UI</a> |
|
|
383 |
</li> |
|
|
384 |
|
|
|
385 |
|
|
|
386 |
|
|
|
387 |
<li data-description="This example shows how to use Dial to animate an image sprite."> |
|
|
388 |
<a href="duck.html">Image Sprite Animation with Dial</a> |
|
|
389 |
</li> |
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
|
394 |
</ul> |
|
|
395 |
</div> |
|
|
396 |
</div> |
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
<div class="sidebox"> |
|
|
401 |
<div class="hd"> |
|
|
402 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
403 |
</div> |
|
|
404 |
|
|
|
405 |
<div class="bd"> |
|
|
406 |
<ul class="examples"> |
|
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
<li data-description="Use the HSL color picker to select a new color. Then chose the color type you like best."> |
|
|
422 |
<a href="../color/hsl-picker.html">HSL Color Picker</a> |
|
|
423 |
</li> |
|
|
424 |
|
|
|
425 |
|
|
|
426 |
</ul> |
|
|
427 |
</div> |
|
|
428 |
</div> |
|
|
429 |
|
|
|
430 |
</div> |
|
|
431 |
</div> |
|
|
432 |
</div> |
|
|
433 |
</div> |
|
|
434 |
|
|
|
435 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
436 |
<script>prettyPrint();</script> |
|
|
437 |
|
|
|
438 |
<script> |
|
|
439 |
YUI.Env.Tests = { |
|
|
440 |
examples: [], |
|
|
441 |
project: '../assets', |
|
|
442 |
assets: '../assets/dial', |
|
|
443 |
name: 'duck', |
|
|
444 |
title: 'Image Sprite Animation with Dial', |
|
|
445 |
newWindow: '', |
|
|
446 |
auto: false |
|
|
447 |
}; |
|
|
448 |
YUI.Env.Tests.examples.push('dial-basic'); |
|
|
449 |
YUI.Env.Tests.examples.push('dial-text-input'); |
|
|
450 |
YUI.Env.Tests.examples.push('dial-image-background'); |
|
|
451 |
YUI.Env.Tests.examples.push('dial-image-surrounding'); |
|
|
452 |
YUI.Env.Tests.examples.push('dial-interactive'); |
|
|
453 |
YUI.Env.Tests.examples.push('duck'); |
|
|
454 |
YUI.Env.Tests.examples.push('hsl-picker'); |
|
|
455 |
|
|
|
456 |
</script> |
|
|
457 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
|
461 |
</body> |
|
|
462 |
</html> |