Forum Moderators: open

Message Too Old, No Replies

clearing the effect of onMouseover with onmouseout

         

bchatterjee

9:11 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



hi,
i have a navigation bar. when the user mouses over any of the items, a sub-navigation bar is populated via onMouseover.

for eg. onMouseOver="showNav2()"

When the user moves his mouse out of the link, i need the sub-navigation bar ot disappear. I am thinking of doing this via onmouseout.

I have tried: onmouseout="clear()"
and onmouseout="null"

this is not working, any suggestions?

TrinkDawg

9:48 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



onmouseout="null" will not work for sure.

onmouseout="clear()" will depend on what is in your clear function. You'll need to write a function that undoes whatever the showNav2 function is doing, if you haven't done so already. Without seeing any code, it's hard to answer specifically.

Purple Martin

10:50 pm on Jan 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's important to put upper and lower case letters in the right places. onmouseout is wrong, onMouseOut is right.

bchatterjee

10:56 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



thanks trink,
i dont have a clear function :-( ... here is what i have so far...
I have this inside the header:

<script language="javascript" type="text/javascript">
function showNav2(){
if (document.all) {
document.all["membership_nav"].style.visibility = "visible"
} else {
document.getElementById("membership_nav").style.visibility = "visible"
}
}
</script>

I have the following in the body: This is the main navigation bar:
<div id="nav">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/membership/" onmouseOver="showNav2()" onmouseout="WHAT DO I PUT HERE?()">Membership</a></li></ul></div>

This is the sub-menu bar. And this is the div that is revealed by the mouseover... i want to hide it with the mouseout.

<div id="membership_nav" style="visibility:hidden;">
<ul>
<li><a href="individual_membership/">Individual Membership</a></li>
<li><a href="small_business_membership/">¦ Small Business Membership</a></li>
</ul> </div>

TrinkDawg

11:49 pm on Jan 19, 2004 (gmt 0)

10+ Year Member



You'll need to either write a new function or change the function you have. You can try changing your function to look like this:

function showNav2(vis){
if (document.all) {
document.all["membership_nav"].style.visibility = vis;
} else {
document.getElementById("membership_nav").style.visibility = vis;
}
}

And then change your link to look like this:

<a href="/membership/" onMouseOver="showNav2('visible');" onMouseOut="showNav2('hidden');">Membership</a>

Just off the top of my head. No testing done.

bchatterjee

8:01 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Trink,
thank you once again, but this did not work. I changed the function as you suggested, but then the sub menu would not display at all.

any other ideas?

Jeeek

12:03 pm on Jan 26, 2004 (gmt 0)

10+ Year Member



works perfect for me..

here's the code I used to test (no doctype, title etc..) - copy&paste and test again

</html>
<head>
<script language="javascript" type="text/javascript">
function showNav2(vis){
if (document.all) {
document.all["membership_nav"].style.visibility = vis;
} else {
document.getElementById("membership_nav").style.visibility = vis;
}
}
</script>
</head>
<body>
<div id="nav">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/membership/" onMouseOver="showNav2('visible');" onMouseOut="showNav2('hidden');">Membership</a></li>

<div id="membership_nav" style="visibility:hidden;">
<ul>
<li><a href="individual_membership/">Individual Membership</a></li>
<li><a href="small_business_membership/">¦ Small Business Membership</a></li>
</ul> </div>
</body>
</html>


but there's one problem I see - how should one click the sub-navigation when you hide it onMouseOut?

bchatterjee

12:30 am on Jan 27, 2004 (gmt 0)

10+ Year Member



you are right! it does work... i must have had come syntax error earlier that did not make it work. it works now. BUT, now i have the problem that Jeeek described...

This hides the sub navigation menu on mouseout.. so the user cannot click on any of the submenu items.

How do I write my code so that the sub menu shows for, say, 5 secs and then disappears?

Jeeek

6:06 pm on Jan 28, 2004 (gmt 0)

10+ Year Member



here is your modified code (I modified test code from above - didn't test it, but it should do the job):

</html>
<head>
<script language="javascript" type="text/javascript">
function showNav2(vis){
if (document.all) {
document.all["membership_nav"].style.visibility = vis;
} else {
document.getElementById("membership_nav").style.visibility = vis;
}
}
</script>
</head>
<body>
<div id="nav">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/membership/" onMouseOver="showNav2('visible');" onMouseOut="javascript:window.setTimeout('showNav2(\'hidden\')',3000);">Membership</a></li>

<div id="membership_nav" style="visibility:hidden;">
<ul>
<li><a href="individual_membership/">Individual Membership</a></li>
<li><a href="small_business_membership/">¦ Small Business Membership</a></li>
</ul> </div>
</body>
</html>

I just added the "javascript:window.setTimeout('functionname(\'parameters\'), 3000')" - passage;

javascript: tells HTML to execute Javascript-code
window.setTimeout("function()",delay): executes the function after given miliseconds (here it's 3000 miliseconds = 3 sec)

the \' - thingy is needed because you run out of quotes here (doublequote used, singlequote used - what now? - use a backslash+singlequote)