Forum Moderators: open

Message Too Old, No Replies

Change layers

         

Regent

7:14 pm on Apr 13, 2004 (gmt 0)

10+ Year Member



I need help with div layers that occupy the same space, but I only want 1 to show as a default, the other 2 would only show up and replace the previously shown div after mousing over a menu item. This is the code I am using:

function toggleMenu(divName) {
if (divName.style.display == "none") {
divName.style.display = "";
divName.style.z-index = "2";
}
else {
divName.style.display = "none";
}

}
The default div is menuOne, the other divs are menuTwo and menuThree. Using a mouseover event - onMouseOver="toggleMenu(menuTwo)" - I want the other divs to replace the first, but I can't get it to work.

Thanks for any help.

Rambo Tribble

2:40 am on Apr 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This does what you have asked:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Div Swap 04.13.04</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
div#d_one{position:absolute;height:400px;width:400px;background:blue;}
div#d_two{position:absolute;height:200px;width:400px;background:red;visibility:hidden;}
div#d_three{position:absolute;top:200px;height:200px;width:400px;background:green;visibility:hidden;}
-->
</style>
<script type="text/javascript">
<!--
function divSwap(){
var bye_bye=document.getElementById("d_one");
var hi_one=document.getElementById("d_two");
var hi_two=document.getElementById("d_three");
bye_bye.style.visibility="hidden";
hi_one.style.visibility="visible";
hi_two.style.visibility="visible";
}
//-->
</script>
</head>
<body>
<div onmouseover="divSwap();">
<div id="d_one"></div>
<div id="d_two"></div>
<div id="d_three"></div>
</div>
</body>
</html>

Obviously, you will have to employ some onmouseout code to return things to the original.

Regent

2:57 pm on Apr 14, 2004 (gmt 0)

10+ Year Member



Thanks. This is very helpful. I do need a little more help, though. I wasn't clear in my original post. Div1 shows up as default when the page loads. Div2 and Div3 are the same size as Div1 and each has their own mouseover space outside of the div area, there is text to mouseover to show the the contents of Div1, Div2, and Div3. So whichever text you mouseover, that Div shows up. So a user can choose to see any of the 3 Divs at any time.

Hope this is more clear.

Thanks again.