View Full Version : Need help with a drop-down menu

03-21-2006, 05:28 PM
Hello from Latvia!!! I'm having a problem with upgrading a small drop-down-menu script which I have put here: http://paste.php.lv/3480. The problem is that when I get onmouseout function, the sub-menus immediately dissapear, my question is this: how can I make the sub-menus stay 1 second after the mouse got from the sub-menu off. I know that I somehow have to use function timer(); but I can't understand, how to connect it together with the code. Previously thanks, and sorry for the bad language.

03-21-2006, 05:51 PM
<script type="text/javascript">
function getElementNumber(el) {
var els = document.getElementsByTagName(el.tagName);
for(var i=0;i<els.length;i++) if(els[i] == el) return i;
return -1;

over = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" over";
sfEls[i].onmouseout=function() {
var me = getElementNumber(this);
this.closeTimer = window.setTimeout("document.getElementsByTagName('LI')["+me+"].className=document.getElementsByTagName('LI')["+me+"].className.replace(/over\b/, '')";
if (window.attachEvent) window.attachEvent("onload", over);
else window.onload = over;
</script> Untested.

03-21-2006, 06:06 PM
Sorry but it doesn't work, it doesn't even display the sub-menus in IE with this code, only in FF (the browsers that I tested) :[

03-21-2006, 08:03 PM
Maybe the functions setInterval() & clearInterval() should help, as I understand, they're something like the timer function!

03-21-2006, 08:11 PM
Gimme a U! Gimme a R! Gimme an L! I want an URL!

03-21-2006, 08:22 PM
Well I have put the version before editing something as you said here: http://www.lfka.lv/index2.htm and the code is here: http://paste.php.lv/3480 (the navigation is changed, I mean the html part, but I left css and js untouched)

The edited version could be found here: http://www.lfka.lv/index3.htm and the code is here: http://paste.php.lv/3484

As you can see, your variant doesn't work as thougt, as well as sub-menus don't work in IE at all.

03-21-2006, 08:54 PM
I'm sorry. Change this line:
this.closeTimer = window.setTimeout("document.getElementsByTagName('LI')["+me+"].className=document.getElementsByTagName('LI')["+me+"].className.replace(/over\b/, '')", 300);Add the bits in red, where 300 is the delay in milliseconds.

03-21-2006, 09:02 PM
I have to admit that I already tried this, only longer delay - 3000, but the edited code still doesn't show up the sub-menus, and the delay doesn't work in FF, neither can I check it in the IE, because of " not showing sub-menu" problem! :[

03-21-2006, 09:08 PM
Please add it to the "edited" page so I can see.

03-21-2006, 09:32 PM
All done (http://www.lfka.lv/index3.htm), I had a small mistake, so it didn't work, but now, the menu's acting really strange, in both browsers, see for yourself, that it leaves the sub-menus on each other, and the sub-menus don't dissapear!

03-22-2006, 09:58 PM
Does anyone have an idea, why the menu's acting so strange?