MenuNav Node Plugin: Left Nav With Submenus With Shadows
This example demonstrates how to add shadows to submenus of a menu built using the MenuNav Node Plugin.
Creating the Shadow HTML
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.
Each shadow will be represented in HTML as a single <div>
element with a class
of yui-menu-shadow
applied, and can easily be created by passing a string of HTML
to Node's create
method. Use the
all
method to
retrieve Node instances for each submenu, and the
append
method to add the
shadow to each submenu.
// Call the "use" method, passing in "node-menunav". This will load the // script and CSS for the MenuNav Node Plugin and all of the required // dependencies. YUI({base:"../../build/", timeout: 10000}).use("node-menunav", function(Y) { // Retrieve the Node instance representing the root menu // (<div id="productsandservices">) var menu = Y.one("#productsandservices"); // Use the "all" method to retrieve the // Node instances representing each submenu. menu.all(".yui-menu").each(function (node) { // Append a shadow element to the bounding box of each submenu node.append('<div class="yui-menu-shadow"></div>'); }); // Call the "plug" method of the Node instance, passing in a reference to the // MenuNav Node Plugin. menu.plug(Y.Plugin.NodeMenuNav); // Show the menu now that it is ready menu.get("ownerDocument").get("documentElement").removeClass("yui-loading"); });
// Call the "use" method, passing in "node-menunav". This will load the // script and CSS for the MenuNav Node Plugin and all of the required // dependencies. YUI({base:"../../build/", timeout: 10000}).use("node-menunav", function(Y) { // Retrieve the Node instance representing the root menu // (<div id="productsandservices">) var menu = Y.one("#productsandservices"); // Use the "all" method to retrieve the // Node instances representing each submenu. menu.all(".yui-menu").each(function (node) { // Append a shadow element to the bounding box of each submenu node.append('<div class="yui-menu-shadow"></div>'); }); // Call the "plug" method of the Node instance, passing in a reference to the // MenuNav Node Plugin. menu.plug(Y.Plugin.NodeMenuNav); // Show the menu now that it is ready menu.get("ownerDocument").get("documentElement").removeClass("yui-loading"); });