src/cm/media/js/lib/yui/yui_3.10.3/docs/node-menunav/node-menunav-5.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Left Nav with Submenus with Shadows</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="../../build/yui/yui-min.js"></script>
    
</head>
<body>
<!--
<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>
-->
<div id="doc">
    <div id="hd">
        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
    </div>
    

            <h1>Example: Left Nav with Submenus with Shadows</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><div class="intro">
    <p>
    This example demonstrates how to add shadows to submenus of a menu built using the MenuNav Node
    Plugin.
    </p>
</div>

<div class="example newwindow">
    <a href="node-menunav-5-example.html" target="_blank" class="button">
        View Example in New Window
    </a>
</div>

<h2>Creating the Shadow HTML</h2>
<p>
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
page's <code>&lt;body&gt;</code> element or to a parent element of the widget in order to apply
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
</p>
<pre class="code prettyprint">&lt;body class=&quot;yui3-skin-sam&quot;&gt; &lt;!-- You need this skin class --&gt;</pre>


<p>
One way to add shadows to submenus is to append decorator elements to the node representing a
submenu's bounding box.  As the name implies, decorator elements add no semantic value to the
markup, but enable additional styles to be applied.  When adding any decorator elements to create
effects like shadows or rounded corners, always add those elements via JavaScript, since it is only
when JavaScript is enabled that a menu's markup is transformed in a drop-down menu system via the
MenuNav Node Plugin.
</p>

<p>
Each shadow will be represented in HTML as a single <code>&#60;div&#62;</code> element with a class
of <code>yui3-menu-shadow</code> applied, and can easily be created by passing a string of HTML
to Node's <a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_create"><code>create</code></a> method.  Use the
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_all"><code>all</code></a> method to
retrieve Node instances for each submenu, and the
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_append"><code>append</code></a> method to add the
shadow to each submenu.
</p>

<pre class="code prettyprint">&#x2F;&#x2F;  Call the &quot;use&quot; method, passing in &quot;node-menunav&quot;.  This will load the
&#x2F;&#x2F;  script and CSS for the MenuNav Node Plugin and all of the required
&#x2F;&#x2F;  dependencies.

YUI().use(&#x27;node-menunav&#x27;, function(Y) {

    &#x2F;&#x2F;  Retrieve the Node instance representing the root menu
    &#x2F;&#x2F;  (&lt;div id=&quot;productsandservices&quot;&gt;)

    var menu = Y.one(&quot;#productsandservices&quot;);


    &#x2F;&#x2F;  Use the &quot;all&quot; method to retrieve the
    &#x2F;&#x2F;  Node instances representing each submenu.

    menu.all(&quot;.yui3-menu&quot;).each(function (node) {

        &#x2F;&#x2F; Append a shadow element to the bounding box of each submenu

        node.append(&#x27;&lt;div class=&quot;yui3-menu-shadow&quot;&gt;&lt;&#x2F;div&gt;&#x27;);

    });


    &#x2F;&#x2F;  Call the &quot;plug&quot; method of the Node instance, passing in a reference to the
    &#x2F;&#x2F;  MenuNav Node Plugin.

    menu.plug(Y.Plugin.NodeMenuNav);

    &#x2F;&#x2F;  Show the menu now that it is ready

    menu.get(&quot;ownerDocument&quot;).get(&quot;documentElement&quot;).removeClass(&quot;yui3-loading&quot;);

});</pre>

<em>Note:</em> In keeping with the
<a href="http://developer.yahoo.com/performance/">Exceptional Performance</a>
team's recommendation, the script block used to instantiate the menu will be
<a href="http://developer.yahoo.com/performance/rules.html#js_bottom">placed at the bottom of the page</a>.
This not only improves performance, it helps ensure that the DOM subtree of the
element representing the root menu
(<code>&#60;div id="productsandservices"&#62;</code>) is ready to be scripted.
</p>

<h2>Styling the Shadow HTML</h2>
<p>
With the shadow element appended to each submenu, the next step is to define the style for the
shadow.  The shadows in this example will be 12% alpha transparent black, and offset from the left,
bottom, and right edges of each submenu's content box by 3px.  To create this effect, start by
setting the <code>position</code> property to <code>absolute</code> and the <code>z-index</code>
property to <code>-1</code>.  This will position each submenu's shadow behind its content box.  For
the 12% alpha transparent black color, set the <code>background-color</code> to <code>#000</code>
and <code>opacity</code> property to <code>.12</code>.
</p>

<p>
Next, set the both the <code>width</code> and <code>height</code> properties to <code>100%</code>
so that the dimensions of the <code>shadow</code> match that of each submenu's bounding box.
(<em>Note:</em>  Setting the <code>height</code> property to <code>100%</code> won't work in IE 6
Strict Mode unless the element's parent element has a height defined.  For this reason the the
MenuNav Node Plugin automatically sets the <code>width</code> and <code>height</code> properties of
each submenu's bounding box to the values of its <code>offsetWidth</code> and
<code>offsetHeight</code> properties before it is made visible.)
</p>

<p>
To create the three-sided effect for the shadow, set the <code>padding</code> property to
<code>1px 3px 0 3px</code>.  As the CSS Box Model specifies that the value for padding is used to
calculate the total width of of an element, the addition of the padding to the shadow makes the
rendered width of the shadow 6px wider (100% + 6px) and 1px taller (100% + 1px) than that of each
submenu's bounding box.  Finally, setting the <code>top</code> property to <code>2px</code> and
the <code>left</code> property to <code>-3px</code> will position the shadow so that its offset
from the left, bottom, and right edge of each submenu's content box by 3px.
</p>

<pre class="code prettyprint">.yui3-menu-shadow {

    position: absolute;
    z-index: -1;
    top: 2px;
    left: -3px;

    background-color: #000;
    opacity: .12;
    filter: alpha(opacity=12);  &#x2F;*  For IE since it doesn&#x27;t implement the CSS3
                                    &quot;opacity&quot; property. *&#x2F;

    padding: 1px 3px 0 3px;
    width: 100%;
    height: 100%;

}</pre>


<p>
Lastly, it is necessary to modify the position and dimensions of the <code>&#60;iframe&#62;</code>
shim, otherwise <code>&#60;select&#62;</code> elements will poke through each submenu's shadow in
IE 6.  Start by setting the <code>z-index</code> property to <code>-2</code> so that the
<code>&#60;iframe&#62;</code> shim is behind the shadow element.  Next, set the <code>padding</code>
property to <code>3px 3px 0 3px</code>.  The core CSS file for MenuNav already sets the
<code>height</code> and <code>width</code> properties to <code>100%</code>, so the addition of the
padding will result in the calculated width and height of the <code>&#60;iframe&#62;</code> shim
being 100% + 6px and 100% + 3px respectively &#151; enough to shim the shadow.  Lastly, setting the
<code>left</code> property to <code>-1</code> syncs the left edge of the
<code>&#60;iframe&#62;</code> with that of the shadow.
</p>

<pre class="code prettyprint">#productsandservices .yui3-menu .yui3-shim {

    z-index: -2;    &#x2F;* Place the iframe shim behind the shadow element *&#x2F;

    &#x2F;*
        Adjust the dimensions of the &lt;iframe&gt; shim to match the shadow,
        otherwise &lt;select&gt; elements will poke through the shadow.
    *&#x2F;

    left: -3px;
    padding: 3px 3px 0 3px;

}</pre>

</div>
            </div>
        </div>

        <div class="yui3-u-1-4">
            <div class="sidebar">
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                        <li data-description="Creating left navigation using the MenuNav Node Plugin.">
                                            <a href="menunav-leftnav.html">Basic Left Nav</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Creating top navigation using the MenuNav Node Plugin">
                                            <a href="node-menunav-2.html">Basic Top Nav</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Creating menu button navigation using the MenuNav Node Plugin">
                                            <a href="node-menunav-3.html">Menu Button Top Nav</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Creating split button navigation using the MenuNav Node Plugin">
                                            <a href="node-menunav-4.html">Split Button Top Nav</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin">
                                            <a href="node-menunav-5.html">Left Nav with Submenus with Shadows</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin">
                                            <a href="node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr">
                                            <a href="node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a>
                                        </li>
                                    
                                
                            </ul>
                        </div>
                    </div>
                

                
            </div>
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

<script>
YUI.Env.Tests = {
    examples: [],
    project: '../assets',
    assets: '../assets/node-menunav',
    name: 'node-menunav-5',
    title: 'Left Nav with Submenus with Shadows',
    newWindow: 'true',
    auto:  false 
};
YUI.Env.Tests.examples.push('menunav-leftnav');
YUI.Env.Tests.examples.push('node-menunav-2');
YUI.Env.Tests.examples.push('node-menunav-3');
YUI.Env.Tests.examples.push('node-menunav-4');
YUI.Env.Tests.examples.push('node-menunav-5');
YUI.Env.Tests.examples.push('node-menunav-6');
YUI.Env.Tests.examples.push('node-menunav-7');

</script>
<script src="../assets/yui/test-runner.js"></script>



</body>
</html>