Im currently trying to learn javascript and have run into a problem when trying to create a dynamic menu. I have been doing examples from a book but I can't seem to find what the problem is in its pages so any help would be appreciated. 
Ive set up an example page at www.strangedarkness.com/menuEx.html
When you hover over 'Navigation' A menu should appear and then dissapear when you remove the cursor but it gets stuck instead of disappearing...
Here's the Javascript/Html.
Code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Menu Example</title>
<style type="text/css">
span {
font-family: verdana, arial;
text-decoration: none;
font-size: 16px;
}
a:link.menuItem {
font-family: verdana, arial;
text-decoration: none;
color: #000000;
font-size: 16px;
border: 1px solid #000000;
}
a:hover.menuItem {
background-color: #000000;
color: #ffffff;
border: 1px solid #cccccc;
}
span.menubar {
position: absolute;
top: 10px;
background: #666666;
}
span.options {
position: relative;
top: 28px;
visibility: hidden;
}
</style>
<script type="text/javascript">
menuVis = false;
function menuShow(e)
{
if (menuVis != true)
{
if (window.event)
{
var elem = event.srcElement;
}
else if (e)
{
var elem = e.target;
}
if (elem.nodeType == 3)
{
elem = elem.parentNode;
}
var sub_menu = "title" + elem.id.substr(5,5);
var elemnew = document.getElementById(sub_menu);
elemnew.style.visibility = "visible";
menuVis=true;
}
}
function hideOnMouseLeave (element, evt)
{
if (element.id.substr(0,5)=='popup')
{
element = element.nextSibling;
if (element.nodeType == "3")
{
element = element.nextSibling;
}
}
if (element.contains && evt.toElement)
{
if (!element.contains(evt.toElement))
{
element.style.visibility = 'hidden';
menuVis=false;
}
}
else if (evt.relatedTarget)
{
if (!contains(element, evt.relatedTarget))
{
element.style.visibilty = 'hidden';
menuVis=false;
}
}
}
function contains (container, containee)
{
do
{
if (container == containee)
{
return true;
}
containee = containee.parentNode;
}
while (containee);
return false;
}
</script>
</head>
<body>
<span class="menubar" id="popup1" onmouseover="return menuShow(event)"
onmouseout="hideOnMouseLeave(this.event)">
Navigation
</span>
<span class="options" onmouseout="hideOnMouseLeave(this.event);"
style="position: absolute; background: #aaaaaa;" id="title1">
<a class="menuItem" href="link1.html">Link 1</a><br />
<a class="menuItem" href="link2.html">Link 2</a><br />
<a class="menuItem" href="link3.html">Link 3</a><br />
<a class="menuItem" href="link4.html">Link 4</a><br />
<a class="menuItem" href="link5.html">Link 5</a>
</span>
</body>
</html>
Last edited by brokensoul2271; 05-11-2005 at 05:18 PM..
|