I’ve been trying to make a drop-down like NBC.com with no success–because I’m constrained to using the following HTML.
I’d like it to be on mouseover–kind of like the UI accordion…
Any help would be greatly appreciated! 🙂
<div class="mainMenu" align="center">
<table cellpadding="0" cellspacing="0" border="0" width="950">
<tr>
<td nowrap><div class="mainMenuDiv menuItem"><a href="http://dev.all4jesus.com/new/#new" class="mainMenuLink" id="1">I'm New</a></td>
<td nowrap><div class="mainMenuDiv menuItem"><a href="http://dev.all4jesus.com/ministries/#ministries" class="mainMenuLink">Ministries</a></div></td>
<td nowrap><div class="mainMenuDiv menuItem"><a href="http://dev.all4jesus.com/beliefs/#beliefs" class="mainMenuLink">Beliefs+Mission</a></div></td>
<td nowrap><div class="mainMenuDiv menuItem"><a href="http://dev.all4jesus.com/listen/#listen" class="mainMenuLink">Listen</a></div></td>
<td nowrap><div class="mainMenuDiv menuItem"><a href="http://dev.all4jesus.com/connect/#contact" class="mainMenuLink">Connect</a></div></td>
<td width="100%"></td>
</tr>
</table>
</div>
<div class="subMenu">
<div id="new">
<h2>I'm New</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
This isn’t perfect, but should give you an idea:
I am presuming that there is a
divunder thesubMenufor each menu item, eg.Explanation:
div‘s insidesubMenu.mouseleaveon all the menu items unconditionally hides all thediv‘s insidesubMenu, even if they are already hidden.mouseenteron all the menu items hides all those samediv‘s, except it shows the one that has identical text inside the menu item’s link and the submenu’sh2header. (There are definitely better ways to do this, but you need some way to correlate the menu item and the submenu. If you have any say about theid‘s, you might be able to use a naming convention that expresses the connections.)Update: Note that there’s a lot of unconditional
hide()going on. For instance, the submenu will go away when the mouse leaves the menu item. To keep the submenu visible while the mouse is on it, addmouseleaveandmouseenterhandlers for"div.subMenu div"as well. To avoid flicker, you might need to keep track of the state of each submenu.Update 2: I’ve added a couple of lines to keep the submenu open while the mouse is in it. YMMV on flicker. This works for me without any change to the tables (it just ignores them). However, the submenu
div‘s need to be positioned right against the menu item, so that the mouse can travel from the menu item to the submenu without it disappearing. In my test code, I set the following to make sure it would work:If this bunches up the text too much, you can add padding in lieu of margin.