Hi all, I'm having issues with a menu. What I've posted here is a simple example. Basically, there is an active menu item (the page you're on) and the content shown in a block below it corresponds to that item ("Item 1" in my example). If you roll over Item 2 or Item 3, the text associated with those two items is shown in the block below them, instead. That works fine.
The part that I can't get figured out is how to make it so the block stays visible when your mouse is anywhere in the block. In other words, if I roll over Item 2, the block below it should change (as it does), and then if I move my mouse down into the block that block should stay visible as long as I'm in the block.
I can't get the timing right. Help? Is there a better way to do this? Thanks!
The part that I can't get figured out is how to make it so the block stays visible when your mouse is anywhere in the block. In other words, if I roll over Item 2, the block below it should change (as it does), and then if I move my mouse down into the block that block should stay visible as long as I'm in the block.
I can't get the timing right. Help? Is there a better way to do this? Thanks!
Code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
function show(shown, active) {
setTimeout("showIt('" + shown + "', '" + active + "')", 100);
}
function hide(hidden, active) {
setTimeout("hideIt('" + hidden + "', '" + active + "')", 100);
}
function showIt(shown, active) {
if (document.getElementById) {
var targetElement = document.getElementById(shown);
var activeElement = document.getElementById(active);
targetElement.style.display = 'block';
activeElement.style.display = 'none';
}
}
function hideIt(hidden, active) {
if (document.getElementById) {
var targetElement = document.getElementById(hidden);
var activeElement = document.getElementById(active);
targetElement.style.display = 'none';
activeElement.style.display = 'block';
}
}
</script>
</head>
<body>
<table width="60%" align="center" style="background-color:pink;margin-top:50px;">
<tr>
<td><div id="outside" style="width:60%;padding:10px;">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>Item 1 (Active)</td>
<td><a href="" onMouseOver="show('bottom_2', 'bottom_1')" onMouseOut="hide('bottom_2', 'bottom_1')">Item 2</a></td>
<td><a href="" onMouseOver="show('bottom_3', 'bottom_1')" onMouseOut="hide('bottom_3', 'bottom_1')">Item 3</a></td>
</tr>
</table>
<div id="bottom" style="margin-top:0;padding:10px;border:1px solid red;">
<div id="bottom_1">Item 1 stuff</div>
<div id="bottom_2" style="display:none" onMouseOver="show('bottom_2', 'bottom_1')" onMouseOut="hide('bottom_2', 'bottom_1')">Item 2 stuff with more stuff</div>
<div id="bottom_3" style="display:none" onMouseOver="show('bottom_3', 'bottom_1')" onMouseOut="hide('bottom_3', 'bottom_1')">Item 3 items</div>
</div>
</div></td>
</tr>
</table>
</body>
</html>