ibjdt
Programmer
- Nov 25, 2002
- 63
i found the menu code below. the original code dropped down sub-menus onmouseover. i changed to onclick and would like to change further so once any menu bar item is clicked, all menus will drop down onmouseover (like the menu bar of windows programs). i attempted several things (the most successful attempt is shown below with my additions between # signs). it's close, but no cigar.
my idea was to use a counter -
onclick -> counter = 1; show sub menu
onmouseover -> if the counter > 0, show sub menu
onmouseout -> close all sub menus; reset counter = 0
is this do-able? if so, i prefer the menus to close onmouseout of any menu item (menu bar main links or sub menus).
thanks.
my idea was to use a counter -
onclick -> counter = 1; show sub menu
onmouseover -> if the counter > 0, show sub menu
onmouseout -> close all sub menus; reset counter = 0
is this do-able? if so, i prefer the menus to close onmouseout of any menu item (menu bar main links or sub menus).
thanks.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html>
<head>
<title>Drop-Down Menu</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="css/default.css">
<!-- dd menu -->
<script type="text/javascript">
<!--
##################
function checkOpen(id) {
if (key > '0') {
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
}
}
##################
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
##################
var key = 0;
##################
// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime();
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
##################
key = '1';
##################
}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}
##################
function reset() { key = '0'; }
##################
// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
// close layer when click-out
//document.onclick = mclose;
// -->
</script>
</head>
<body>
<h1>DropDown Menu</h1>
<p>This menu can be located anywhere on a page:</p>
<ul id="sddm">
<li><a href="#" onmouseover="checkOpen('m1')" onclick="mopen('m1')" onmouseout="mclosetime()">Home</a>
<div id="m1" onmouseover="mcancelclosetime()" onmouseout="reset(); mclosetime();">
<a href="#">HTML DropDown</a>
<a href="#">DHTML DropDown menu</a>
<a href="#">JavaScript DropDown</a>
<a href="#">DropDown Menu</a>
<a href="#">CSS DropDown</a>
</div>
</li>
<li><a href="#" onmouseover="checkOpen('m2')" onclick="mopen('m2')" onmouseout="mclosetime()">Download</a>
<div id="m2" onmouseover="mcancelclosetime()" onmouseout="reset(); mclosetime();">
<a href="#">ASP Dropdown</a>
<a href="#">Pulldown menu</a>
<a href="#">AJAX dropdown</a>
<a href="#">DIV dropdown</a>
</div>
</li>
<li><a href="#" onclick="mopen('m3')" onmouseout="mclosetime()">Order</a>
<div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">Visa Credit Card</a>
<a href="#">Paypal</a>
</div>
</li>
<li><a href="#" onclick="mopen('m4')" onmouseout="mclosetime()">Help</a>
<div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">Download Help File</a>
<a href="#">Read online</a>
</div>
</li>
<li><a href="#" onclick="mopen('m5')" onmouseout="mclosetime()">Contact</a>
<div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
<a href="#">E-mail</a>
<a href="#">Submit Request Form</a>
<a href="#">Call Center</a>
</div>
</li>
</ul>
<div style="clear:both"></div>
<div style="clear:both"></div>
<p>If you are looking for advanced script, see the <a href="[URL unfurl="true"]http://javascript-array.com/scripts/multi_level_drop_down_menu/?sddm">Multi-Level[/URL] Drop-Down Menu</a> based on simple treelike unordered list.
<p>If you want to use this script on your page, please place link to [URL unfurl="true"]http://javascript-array.com[/URL] at one of your pages.
<p>© Copyright 2006-2007 <a href="[URL unfurl="true"]http://javascript-array.com/">javascript-array.com</p>[/URL]
</body>
</html>