|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Left Nav with Submenus with Shadows</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: Left Nav with Submenus with Shadows</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 add shadows to submenus of a menu built using the MenuNav Node |
|
|
31 |
Plugin. |
|
|
32 |
</p> |
|
|
33 |
</div> |
|
|
34 |
|
|
|
35 |
<div class="example newwindow"> |
|
|
36 |
<a href="node-menunav-5-example.html" target="_blank" class="button"> |
|
|
37 |
View Example in New Window |
|
|
38 |
</a> |
|
|
39 |
</div> |
|
|
40 |
|
|
|
41 |
<h2>Creating the Shadow HTML</h2> |
|
|
42 |
<p> |
|
|
43 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
44 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
45 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
46 |
</p> |
|
|
47 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
<p> |
|
|
51 |
One way to add shadows to submenus is to append decorator elements to the node representing a |
|
|
52 |
submenu's bounding box. As the name implies, decorator elements add no semantic value to the |
|
|
53 |
markup, but enable additional styles to be applied. When adding any decorator elements to create |
|
|
54 |
effects like shadows or rounded corners, always add those elements via JavaScript, since it is only |
|
|
55 |
when JavaScript is enabled that a menu's markup is transformed in a drop-down menu system via the |
|
|
56 |
MenuNav Node Plugin. |
|
|
57 |
</p> |
|
|
58 |
|
|
|
59 |
<p> |
|
|
60 |
Each shadow will be represented in HTML as a single <code><div></code> element with a class |
|
|
61 |
of <code>yui3-menu-shadow</code> applied, and can easily be created by passing a string of HTML |
|
|
62 |
to Node's <a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_create"><code>create</code></a> method. Use the |
|
|
63 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_all"><code>all</code></a> method to |
|
|
64 |
retrieve Node instances for each submenu, and the |
|
|
65 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_append"><code>append</code></a> method to add the |
|
|
66 |
shadow to each submenu. |
|
|
67 |
</p> |
|
|
68 |
|
|
|
69 |
<pre class="code prettyprint">// Call the "use" method, passing in "node-menunav". This will load the |
|
|
70 |
// script and CSS for the MenuNav Node Plugin and all of the required |
|
|
71 |
// dependencies. |
|
|
72 |
|
|
|
73 |
YUI().use('node-menunav', function(Y) { |
|
|
74 |
|
|
|
75 |
// Retrieve the Node instance representing the root menu |
|
|
76 |
// (<div id="productsandservices">) |
|
|
77 |
|
|
|
78 |
var menu = Y.one("#productsandservices"); |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
// Use the "all" method to retrieve the |
|
|
82 |
// Node instances representing each submenu. |
|
|
83 |
|
|
|
84 |
menu.all(".yui3-menu").each(function (node) { |
|
|
85 |
|
|
|
86 |
// Append a shadow element to the bounding box of each submenu |
|
|
87 |
|
|
|
88 |
node.append('<div class="yui3-menu-shadow"></div>'); |
|
|
89 |
|
|
|
90 |
}); |
|
|
91 |
|
|
|
92 |
|
|
|
93 |
// Call the "plug" method of the Node instance, passing in a reference to the |
|
|
94 |
// MenuNav Node Plugin. |
|
|
95 |
|
|
|
96 |
menu.plug(Y.Plugin.NodeMenuNav); |
|
|
97 |
|
|
|
98 |
// Show the menu now that it is ready |
|
|
99 |
|
|
|
100 |
menu.get("ownerDocument").get("documentElement").removeClass("yui3-loading"); |
|
|
101 |
|
|
|
102 |
});</pre> |
|
|
103 |
|
|
|
104 |
<em>Note:</em> In keeping with the |
|
|
105 |
<a href="http://developer.yahoo.com/performance/">Exceptional Performance</a> |
|
|
106 |
team's recommendation, the script block used to instantiate the menu will be |
|
|
107 |
<a href="http://developer.yahoo.com/performance/rules.html#js_bottom">placed at the bottom of the page</a>. |
|
|
108 |
This not only improves performance, it helps ensure that the DOM subtree of the |
|
|
109 |
element representing the root menu |
|
|
110 |
(<code><div id="productsandservices"></code>) is ready to be scripted. |
|
|
111 |
</p> |
|
|
112 |
|
|
|
113 |
<h2>Styling the Shadow HTML</h2> |
|
|
114 |
<p> |
|
|
115 |
With the shadow element appended to each submenu, the next step is to define the style for the |
|
|
116 |
shadow. The shadows in this example will be 12% alpha transparent black, and offset from the left, |
|
|
117 |
bottom, and right edges of each submenu's content box by 3px. To create this effect, start by |
|
|
118 |
setting the <code>position</code> property to <code>absolute</code> and the <code>z-index</code> |
|
|
119 |
property to <code>-1</code>. This will position each submenu's shadow behind its content box. For |
|
|
120 |
the 12% alpha transparent black color, set the <code>background-color</code> to <code>#000</code> |
|
|
121 |
and <code>opacity</code> property to <code>.12</code>. |
|
|
122 |
</p> |
|
|
123 |
|
|
|
124 |
<p> |
|
|
125 |
Next, set the both the <code>width</code> and <code>height</code> properties to <code>100%</code> |
|
|
126 |
so that the dimensions of the <code>shadow</code> match that of each submenu's bounding box. |
|
|
127 |
(<em>Note:</em> Setting the <code>height</code> property to <code>100%</code> won't work in IE 6 |
|
|
128 |
Strict Mode unless the element's parent element has a height defined. For this reason the the |
|
|
129 |
MenuNav Node Plugin automatically sets the <code>width</code> and <code>height</code> properties of |
|
|
130 |
each submenu's bounding box to the values of its <code>offsetWidth</code> and |
|
|
131 |
<code>offsetHeight</code> properties before it is made visible.) |
|
|
132 |
</p> |
|
|
133 |
|
|
|
134 |
<p> |
|
|
135 |
To create the three-sided effect for the shadow, set the <code>padding</code> property to |
|
|
136 |
<code>1px 3px 0 3px</code>. As the CSS Box Model specifies that the value for padding is used to |
|
|
137 |
calculate the total width of of an element, the addition of the padding to the shadow makes the |
|
|
138 |
rendered width of the shadow 6px wider (100% + 6px) and 1px taller (100% + 1px) than that of each |
|
|
139 |
submenu's bounding box. Finally, setting the <code>top</code> property to <code>2px</code> and |
|
|
140 |
the <code>left</code> property to <code>-3px</code> will position the shadow so that its offset |
|
|
141 |
from the left, bottom, and right edge of each submenu's content box by 3px. |
|
|
142 |
</p> |
|
|
143 |
|
|
|
144 |
<pre class="code prettyprint">.yui3-menu-shadow { |
|
|
145 |
|
|
|
146 |
position: absolute; |
|
|
147 |
z-index: -1; |
|
|
148 |
top: 2px; |
|
|
149 |
left: -3px; |
|
|
150 |
|
|
|
151 |
background-color: #000; |
|
|
152 |
opacity: .12; |
|
|
153 |
filter: alpha(opacity=12); /* For IE since it doesn't implement the CSS3 |
|
|
154 |
"opacity" property. */ |
|
|
155 |
|
|
|
156 |
padding: 1px 3px 0 3px; |
|
|
157 |
width: 100%; |
|
|
158 |
height: 100%; |
|
|
159 |
|
|
|
160 |
}</pre> |
|
|
161 |
|
|
|
162 |
|
|
|
163 |
<p> |
|
|
164 |
Lastly, it is necessary to modify the position and dimensions of the <code><iframe></code> |
|
|
165 |
shim, otherwise <code><select></code> elements will poke through each submenu's shadow in |
|
|
166 |
IE 6. Start by setting the <code>z-index</code> property to <code>-2</code> so that the |
|
|
167 |
<code><iframe></code> shim is behind the shadow element. Next, set the <code>padding</code> |
|
|
168 |
property to <code>3px 3px 0 3px</code>. The core CSS file for MenuNav already sets the |
|
|
169 |
<code>height</code> and <code>width</code> properties to <code>100%</code>, so the addition of the |
|
|
170 |
padding will result in the calculated width and height of the <code><iframe></code> shim |
|
|
171 |
being 100% + 6px and 100% + 3px respectively — enough to shim the shadow. Lastly, setting the |
|
|
172 |
<code>left</code> property to <code>-1</code> syncs the left edge of the |
|
|
173 |
<code><iframe></code> with that of the shadow. |
|
|
174 |
</p> |
|
|
175 |
|
|
|
176 |
<pre class="code prettyprint">#productsandservices .yui3-menu .yui3-shim { |
|
|
177 |
|
|
|
178 |
z-index: -2; /* Place the iframe shim behind the shadow element */ |
|
|
179 |
|
|
|
180 |
/* |
|
|
181 |
Adjust the dimensions of the <iframe> shim to match the shadow, |
|
|
182 |
otherwise <select> elements will poke through the shadow. |
|
|
183 |
*/ |
|
|
184 |
|
|
|
185 |
left: -3px; |
|
|
186 |
padding: 3px 3px 0 3px; |
|
|
187 |
|
|
|
188 |
}</pre> |
|
|
189 |
|
|
|
190 |
</div> |
|
|
191 |
</div> |
|
|
192 |
</div> |
|
|
193 |
|
|
|
194 |
<div class="yui3-u-1-4"> |
|
|
195 |
<div class="sidebar"> |
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
<div class="sidebox"> |
|
|
200 |
<div class="hd"> |
|
|
201 |
<h2 class="no-toc">Examples</h2> |
|
|
202 |
</div> |
|
|
203 |
|
|
|
204 |
<div class="bd"> |
|
|
205 |
<ul class="examples"> |
|
|
206 |
|
|
|
207 |
|
|
|
208 |
<li data-description="Creating left navigation using the MenuNav Node Plugin."> |
|
|
209 |
<a href="menunav-leftnav.html">Basic Left Nav</a> |
|
|
210 |
</li> |
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
<li data-description="Creating top navigation using the MenuNav Node Plugin"> |
|
|
215 |
<a href="node-menunav-2.html">Basic Top Nav</a> |
|
|
216 |
</li> |
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
<li data-description="Creating menu button navigation using the MenuNav Node Plugin"> |
|
|
221 |
<a href="node-menunav-3.html">Menu Button Top Nav</a> |
|
|
222 |
</li> |
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
<li data-description="Creating split button navigation using the MenuNav Node Plugin"> |
|
|
227 |
<a href="node-menunav-4.html">Split Button Top Nav</a> |
|
|
228 |
</li> |
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
<li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin"> |
|
|
233 |
<a href="node-menunav-5.html">Left Nav with Submenus with Shadows</a> |
|
|
234 |
</li> |
|
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
|
238 |
<li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin"> |
|
|
239 |
<a href="node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a> |
|
|
240 |
</li> |
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
<li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr"> |
|
|
245 |
<a href="node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a> |
|
|
246 |
</li> |
|
|
247 |
|
|
|
248 |
|
|
|
249 |
</ul> |
|
|
250 |
</div> |
|
|
251 |
</div> |
|
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
</div> |
|
|
256 |
</div> |
|
|
257 |
</div> |
|
|
258 |
</div> |
|
|
259 |
|
|
|
260 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
261 |
<script>prettyPrint();</script> |
|
|
262 |
|
|
|
263 |
<script> |
|
|
264 |
YUI.Env.Tests = { |
|
|
265 |
examples: [], |
|
|
266 |
project: '../assets', |
|
|
267 |
assets: '../assets/node-menunav', |
|
|
268 |
name: 'node-menunav-5', |
|
|
269 |
title: 'Left Nav with Submenus with Shadows', |
|
|
270 |
newWindow: 'true', |
|
|
271 |
auto: false |
|
|
272 |
}; |
|
|
273 |
YUI.Env.Tests.examples.push('menunav-leftnav'); |
|
|
274 |
YUI.Env.Tests.examples.push('node-menunav-2'); |
|
|
275 |
YUI.Env.Tests.examples.push('node-menunav-3'); |
|
|
276 |
YUI.Env.Tests.examples.push('node-menunav-4'); |
|
|
277 |
YUI.Env.Tests.examples.push('node-menunav-5'); |
|
|
278 |
YUI.Env.Tests.examples.push('node-menunav-6'); |
|
|
279 |
YUI.Env.Tests.examples.push('node-menunav-7'); |
|
|
280 |
|
|
|
281 |
</script> |
|
|
282 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
</body> |
|
|
287 |
</html> |