|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Creating an Animated Panel</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: Creating an Animated Panel</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> |
|
|
30 |
This example demonstrates how to instantiate a panel and use it in conjunction with the <code>"transition"</code> module to create an animated panel. |
|
|
31 |
</p> |
|
|
32 |
</div> |
|
|
33 |
|
|
|
34 |
<div class="example newwindow"> |
|
|
35 |
<a href="panel-animate-example.html" target="_blank" class="button"> |
|
|
36 |
View Example in New Window |
|
|
37 |
</a> |
|
|
38 |
</div> |
|
|
39 |
|
|
|
40 |
<h2>Creating an animated panel</h2> |
|
|
41 |
|
|
|
42 |
<h3>Setting Up The YUI Instance</h3> |
|
|
43 |
|
|
|
44 |
<p> |
|
|
45 |
To create an instance of a Panel on your page, the only module you need to request is the <code>panel</code> module. The <code>panel</code> module will pull in the <code>widget</code>, <code>widget-stack</code>, <code>widget-position</code>, <code>widget-position-align</code>, <code>widget-position-constrain</code>, <code>widget-stdmod</code>, <code>widget-buttons</code>, <code>widget-modality</code> and <code>widget-autohide</code> extensions it uses. |
|
|
46 |
</p> |
|
|
47 |
|
|
|
48 |
<p> |
|
|
49 |
For this example, we also need to use the <code>transition</code> module. This module allows us to easily create animations using CSS3 transitions, with a JavaScript timer fallback. |
|
|
50 |
</p> |
|
|
51 |
|
|
|
52 |
<pre class="code prettyprint lang-javascript">YUI().use('panel', 'transition', function (Y) { |
|
|
53 |
// We'll write example code here |
|
|
54 |
});</pre> |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
<p> |
|
|
58 |
Note, using the <code>panel</code> module, will also pull down the default CSS required for panel. The CSS that styles the Panel requires you to have the class <code>yui3-skin-sam</code> on a parent element, commonly the <code><body></code> tag. |
|
|
59 |
</p> |
|
|
60 |
|
|
|
61 |
<p> |
|
|
62 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
63 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
64 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
65 |
</p> |
|
|
66 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
67 |
|
|
|
68 |
|
|
|
69 |
<h3>Instantiating the Panel</h3> |
|
|
70 |
|
|
|
71 |
<p> |
|
|
72 |
For this example, we'll instantiate a modal panel, set its visibility to false, and set some CSS properties. The following HTML will be used as the markup for the panel. |
|
|
73 |
</p> |
|
|
74 |
|
|
|
75 |
<pre class="code prettyprint lang-html"><div id="panelContent"> |
|
|
76 |
<div class="yui3-widget-hd"> |
|
|
77 |
Showing an animated panel |
|
|
78 |
</div> |
|
|
79 |
<div class="yui3-widget-bd"> |
|
|
80 |
<p>Making panels animate is easy with the "transition" module!</p> |
|
|
81 |
</div> |
|
|
82 |
</div></pre> |
|
|
83 |
|
|
|
84 |
|
|
|
85 |
<p>The JavaScript to instantiate the panel is as follows:</p> |
|
|
86 |
|
|
|
87 |
<pre class="code prettyprint lang-javascript">var panel = new Y.Panel({ |
|
|
88 |
srcNode: '#panelContent', |
|
|
89 |
width : 330, |
|
|
90 |
xy : [300, -300], |
|
|
91 |
zIndex : 5, |
|
|
92 |
modal : true, |
|
|
93 |
visible: false, |
|
|
94 |
render : true, |
|
|
95 |
buttons: [ |
|
|
96 |
{ |
|
|
97 |
value : 'Close the panel', |
|
|
98 |
section: 'footer', |
|
|
99 |
action : function (e) { |
|
|
100 |
e.preventDefault(); |
|
|
101 |
hidePanel(); |
|
|
102 |
} |
|
|
103 |
} |
|
|
104 |
] |
|
|
105 |
});</pre> |
|
|
106 |
|
|
|
107 |
|
|
|
108 |
<h3>Adding Animation</h3> |
|
|
109 |
|
|
|
110 |
<p> |
|
|
111 |
To create the animations, we need to set up transition properties on the panel's <code>boundingBox</code>. These properties consist of key/value pairs of CSS properties that we want to alter. |
|
|
112 |
</p> |
|
|
113 |
|
|
|
114 |
<p> |
|
|
115 |
We define two methods <code>showPanel()</code> and <code>hidePanel()</code> that define transitions. We could also use the <code>visibleChange</code> event to toggle the animation based on the state. However, the benefit of this method is that it allows us to use callback functions after the <code>transition</code> has ended. |
|
|
116 |
</p> |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
<pre class="code prettyprint lang-javascript">function showPanel() { |
|
|
120 |
panel.show(); |
|
|
121 |
bb.transition({ |
|
|
122 |
duration: 0.5, |
|
|
123 |
top : '80px' |
|
|
124 |
}); |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
function hidePanel() { |
|
|
128 |
bb.transition({ |
|
|
129 |
duration: 0.5, |
|
|
130 |
top : '-300px' |
|
|
131 |
}, function () { |
|
|
132 |
panel.hide(); |
|
|
133 |
}); |
|
|
134 |
}</pre> |
|
|
135 |
|
|
|
136 |
|
|
|
137 |
<h3>Adding Buttons to toggle visibility</h3> |
|
|
138 |
|
|
|
139 |
<p> |
|
|
140 |
Finally, we create two buttons, one to show the panel and one to hide it. |
|
|
141 |
</p> |
|
|
142 |
|
|
|
143 |
<p> |
|
|
144 |
The button to close the panel was specified in the instantiation of the panel. The button to open the panel can be defined as: |
|
|
145 |
</p> |
|
|
146 |
|
|
|
147 |
<pre class="code prettyprint lang-javascript">// Add Panel show button. |
|
|
148 |
openBtn.on('click', function (e) { |
|
|
149 |
showPanel(); |
|
|
150 |
});</pre> |
|
|
151 |
|
|
|
152 |
|
|
|
153 |
<h3>Complete Example Source</h3> |
|
|
154 |
|
|
|
155 |
<pre class="code prettyprint"><style type="text/css"> |
|
|
156 |
|
|
|
157 |
.yui3-panel { |
|
|
158 |
outline: none; |
|
|
159 |
} |
|
|
160 |
|
|
|
161 |
.yui3-panel #panelContent { |
|
|
162 |
-webkit-box-shadow: 0px 0px 2px black; |
|
|
163 |
-moz-box-shadow: 0px 0px 2px black; |
|
|
164 |
box-shadow: 0px 0px 2px black; |
|
|
165 |
} |
|
|
166 |
.yui3-panel #panelContent .yui3-widget-hd { |
|
|
167 |
font-weight: bold; |
|
|
168 |
padding: 5px; |
|
|
169 |
} |
|
|
170 |
|
|
|
171 |
#panelContent .yui3-widget-bd { |
|
|
172 |
padding: 15px; |
|
|
173 |
background: white; |
|
|
174 |
text-align: center; |
|
|
175 |
} |
|
|
176 |
|
|
|
177 |
#panelContent.yui3-widget-loading { |
|
|
178 |
display: none; |
|
|
179 |
} |
|
|
180 |
|
|
|
181 |
.yui3-skin-sam .yui3-widget-mask { |
|
|
182 |
background-color: #223460; |
|
|
183 |
opacity: 0.9; |
|
|
184 |
} |
|
|
185 |
|
|
|
186 |
</style> |
|
|
187 |
|
|
|
188 |
<h2>Creating an animated panel using transitions</h2> |
|
|
189 |
|
|
|
190 |
<p> |
|
|
191 |
This example shows an animated modal form. |
|
|
192 |
<button id="openButton">Open Panel</button> |
|
|
193 |
</p> |
|
|
194 |
|
|
|
195 |
<p> |
|
|
196 |
Now let's fill this space with some text so that the modality kicks in. |
|
|
197 |
</p> |
|
|
198 |
|
|
|
199 |
<p> |
|
|
200 |
Vestibulum quis purus metus. Quisque in adipiscing erat. Class aptent taciti |
|
|
201 |
sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In vitae |
|
|
202 |
lacus tellus, non iaculis arcu. Donec nec risus diam. Vivamus sed mauris eros, |
|
|
203 |
nec ultrices nibh. Phasellus scelerisque aliquet mauris, faucibus aliquam ipsum |
|
|
204 |
tempor quis. Integer quis risus sed tellus ornare venenatis quis ut magna. |
|
|
205 |
Integer erat mauris, hendrerit faucibus iaculis eu, feugiat vitae massa. Aliquam |
|
|
206 |
mi augue, tincidunt id porttitor ut, lacinia sed eros. Vestibulum ante ipsum |
|
|
207 |
primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed elementum |
|
|
208 |
fringilla urna vel cursus. Etiam et suscipit eros. In ornare lacinia est, sed |
|
|
209 |
bibendum ligula blandit nec. Vestibulum tristique pulvinar nunc, quis lacinia |
|
|
210 |
eros facilisis vel. Duis tristique porttitor risus, vel laoreet ligula mollis |
|
|
211 |
vitae. Nam ornare justo a turpis mattis cursus. |
|
|
212 |
</p> |
|
|
213 |
|
|
|
214 |
<div id="panelContent" class="yui3-widget-loading"> |
|
|
215 |
<div class="yui3-widget-hd"> |
|
|
216 |
Showing an animated panel |
|
|
217 |
</div> |
|
|
218 |
<div class="yui3-widget-bd"> |
|
|
219 |
<p>Making panels animate is easy with the "transition" module!</p> |
|
|
220 |
</div> |
|
|
221 |
</div> |
|
|
222 |
|
|
|
223 |
|
|
|
224 |
<script type="text/javascript"> |
|
|
225 |
YUI().use('transition', 'panel', function (Y) { |
|
|
226 |
|
|
|
227 |
var openBtn = Y.one('#openButton'), |
|
|
228 |
panel, bb; |
|
|
229 |
|
|
|
230 |
function showPanel() { |
|
|
231 |
panel.show(); |
|
|
232 |
bb.transition({ |
|
|
233 |
duration: 0.5, |
|
|
234 |
top : '80px' |
|
|
235 |
}); |
|
|
236 |
} |
|
|
237 |
|
|
|
238 |
function hidePanel() { |
|
|
239 |
bb.transition({ |
|
|
240 |
duration: 0.5, |
|
|
241 |
top : '-300px' |
|
|
242 |
}, function () { |
|
|
243 |
panel.hide(); |
|
|
244 |
}); |
|
|
245 |
} |
|
|
246 |
|
|
|
247 |
panel = new Y.Panel({ |
|
|
248 |
srcNode: '#panelContent', |
|
|
249 |
width : 330, |
|
|
250 |
xy : [300, -300], |
|
|
251 |
zIndex : 5, |
|
|
252 |
modal : true, |
|
|
253 |
visible: false, |
|
|
254 |
render : true, |
|
|
255 |
buttons: [ |
|
|
256 |
{ |
|
|
257 |
value : 'Close the panel', |
|
|
258 |
section: 'footer', |
|
|
259 |
action : function (e) { |
|
|
260 |
e.preventDefault(); |
|
|
261 |
hidePanel(); |
|
|
262 |
} |
|
|
263 |
} |
|
|
264 |
] |
|
|
265 |
}); |
|
|
266 |
|
|
|
267 |
bb = panel.get('boundingBox'); |
|
|
268 |
|
|
|
269 |
openBtn.on('click', function (e) { |
|
|
270 |
showPanel(); |
|
|
271 |
}); |
|
|
272 |
|
|
|
273 |
}); |
|
|
274 |
|
|
|
275 |
</script></pre> |
|
|
276 |
|
|
|
277 |
</div> |
|
|
278 |
</div> |
|
|
279 |
</div> |
|
|
280 |
|
|
|
281 |
<div class="yui3-u-1-4"> |
|
|
282 |
<div class="sidebar"> |
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
<div class="sidebox"> |
|
|
287 |
<div class="hd"> |
|
|
288 |
<h2 class="no-toc">Examples</h2> |
|
|
289 |
</div> |
|
|
290 |
|
|
|
291 |
<div class="bd"> |
|
|
292 |
<ul class="examples"> |
|
|
293 |
|
|
|
294 |
|
|
|
295 |
<li data-description="Shows how to instantiate multiple Panel instances, and use nested modality to interact with a Datatable."> |
|
|
296 |
<a href="panel-form.html">Creating a Modal Form</a> |
|
|
297 |
</li> |
|
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
<li data-description="Shows how to create a panel that animates as it is shown and hidden"> |
|
|
302 |
<a href="panel-animate.html">Creating an Animated Panel</a> |
|
|
303 |
</li> |
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
<li data-description="Shows how to create a dialog instance that can be reused for multiple messages and confirmations."> |
|
|
308 |
<a href="dialog.html">Creating a Reusable Dialog</a> |
|
|
309 |
</li> |
|
|
310 |
|
|
|
311 |
|
|
|
312 |
</ul> |
|
|
313 |
</div> |
|
|
314 |
</div> |
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
</div> |
|
|
319 |
</div> |
|
|
320 |
</div> |
|
|
321 |
</div> |
|
|
322 |
|
|
|
323 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
324 |
<script>prettyPrint();</script> |
|
|
325 |
|
|
|
326 |
<script> |
|
|
327 |
YUI.Env.Tests = { |
|
|
328 |
examples: [], |
|
|
329 |
project: '../assets', |
|
|
330 |
assets: '../assets/panel', |
|
|
331 |
name: 'panel-animate', |
|
|
332 |
title: 'Creating an Animated Panel', |
|
|
333 |
newWindow: 'true', |
|
|
334 |
auto: false |
|
|
335 |
}; |
|
|
336 |
YUI.Env.Tests.examples.push('panel-form'); |
|
|
337 |
YUI.Env.Tests.examples.push('panel-animate'); |
|
|
338 |
YUI.Env.Tests.examples.push('dialog'); |
|
|
339 |
|
|
|
340 |
</script> |
|
|
341 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
|
345 |
</body> |
|
|
346 |
</html> |