My first post is here. I want to make a horizontal menu with a submenu sliding down on hover. I know I can use jQuery, but that should practice my javascript skills.
I am using the following code:
var up = new Array()
var down = new Array()
var submenustart
function titleover(headmenu, inter)
{
submenu = headmenu.lastChild
up[inter] = window.clearInterval(up[inter])
down[inter] = window.setInterval("slidedown(submenu)",1)
}
function slidedown(submenu)
{
if(submenu.offsetTop < submenustart)
{
submenu.style.top = submenu.offsetTop + 1 + "px"
}
}
function titleout(headmenu, inter)
{
submenu = headmenu.lastChild
down[inter] = window.clearInterval(down[inter])
up[inter] = window.setInterval("slideup(submenu)", 1)
}
function slideup(submenu)
{
if(submenu.offsetTop > submenustart - submenu.clientHeight + 1)
{
submenu.style.top = submenu.offsetTop - 1 + "px"
}
}
The submenustart variable gets the value in another function that is not relevant to my question.
HTML looks like this:
<table class="hoofding" id="hoofding">
<tr>
<td onmouseover="titleover(this, 0)" onmouseout="titleout(this, 0)"><a href="#" class="hoofdinglink" id="hoofd1">AAAA</a>
<table class="menu">
<tr><td><a href="...">1111</a></td></tr>
<tr><td><a href="...">2222</a></td></tr>
<tr><td><a href="...">3333</a></td></tr>
</table></td>
<td onmouseover="titleover(this, 1)" onmouseout="titleout(this, 1)"><a href="#" class="hoofdinglink">BBBB</a>
<table class="menu">
<tr><td><a href="...">1111</a></td></tr>
<tr><td><a href="...">2222</a></td></tr>
<tr><td><a href="...">3333</a></td></tr>
<tr><td><a href="...">4444</a></td></tr>
<tr><td><a href="...">5555</a></td></tr>
</table></td>
...
</tr>
</table>
What happens is this:
If I go over and exit (for ex) menu A, it works fine. If I now go through menu B, then now the interval applied to B is applied to A. Now to B. now 2 interval functions are applied. The first one is for A and the new one caused by hovering over B. If I went to A, all intervals now apply to A.
, .
.