robjay
asked on
relative positioning when creating a mouseover dynamic drop down table
This code was dropped in a post some time back. I find it useful, but I'm unable to make the drop down relative when I change the location of the mouseover text (I've added some <BR>s to move it down some). The drop down box still appears at the top of the HTML page - I have changed some of the position values but then the mouseout doesn't appear to work:
<HTML>
<HEAD>
<TITLE>Drop Down Menu</TITLE>
<style type="text/css">
td {font-family:verdana, san-serif, arial;font-size:10pt;font- weight:bol d;}
.spcls {background:#EEEEEE;font-f amily:verd ana, san-serif, arial;font-size:10pt;font- weight:bol d;}
#list{position:absolute;z- Index:2}
</style>
<script language="javascript">
showlist = false
timeoutID = ''
list = new Array()
list[0] = new Array('Option1_1','Option1 _2','Optio n1_3'); // Submenu for menu one
list[1] = new Array('Option2_1.','Option 2_2','Opti on2_3'); // Submenu for menu two
list[2] = new Array('Option3_1.','Option 3_2','Opti on3_3');// Submenu for menu three
list[3] = new Array('Option4_1.','Option 4_2','Opti on4_3');// Submenu for menu four
listUrl = new Array()
listUrl[0] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list one
listUrl[1] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list two
listUrl[2] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list three
listUrl[3] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list four
function listme(val,divposition)
{
window.clearTimeout(timeou tID)
bodystart = '<table border=1 >';
bodypart = '';
for(i=0; i< list[val].length; i++)
{
bodypart = bodypart + '<tr valign="top" align="center"><td><a href="'+listUrl[val][i]+'" onmouseout="returnback()" >'+ list[val][i] +'</a></td></tr>';
}
bodyend = '</table>';
if(document.all)
{
document.all.list.innerHTM L = bodystart + bodypart + bodyend;
document.all.list.style.to p = 40;
document.all.list.style.le ft = divposition
if(document.all.list.style .pixelLeft +100 >= screen.width)
{
document.all.list.style.le ft = screen.width-125
}
}
if(document.layers)
{
mylayer = eval(document.list);
mylayer.document.writeln(b odystart + bodypart + bodyend);
mylayer.moveTo(divposition ,40)
if(mylayer.pageX+mylayer.c lip.right >= window.outerWidth)
{
mylayer.moveTo(window.oute rWidth-125 ,40)
}
mylayer.document.close();
}
timeoutID = window.setTimeout("deletem e();", 1700);
}
function deleteme()
{
if(!showlist)
{
if(document.all)
{
document.all.list.innerHTM L = ''
document.all.list.style.to p = 40;
document.all.list.style.le ft = 0;
}
if(document.layers)
{
mylayer = eval(document.list);
mylayer.document.write('') ;
mylayer.moveTo(0,40);
mylayer.document.close();
}
}
else
{
window.setTimeout("deletem e();", 800);
}
}
function returnback()
{
return;
}
function setshow()
{
showlist = true
}
function sethide()
{
showlist = false;
}
</script>
</HEAD>
<BODY >
<BR><BR><BR><BR><BR><BR><B R><BR><BR> <BR><BR>
<table id="tbl" align="left" border="1" >
<tr valign="top" align="left">
<td><a href="javascript:listme(0, 25)" onmouseover="javascript:li stme(0,25) ">Menu 1</a></td>
<td><a href="javascript:listme(1, 90)" onmouseover="javascript:li stme(1,90) ">Menu 2</a></td>
<td><a href="javascript:listme(2, 150)" onmouseover="javascript:li stme(2,150 )">Menu 3</a></td>
<td><a href="javascript:listme(3, 225)" onmouseover="javascript:li stme(3,225 )">Menu 4</a></td>
</tr>
</table><br>
<div id="list" style="position:absolute;w idth:150" onmouseover="setshow()" onmouseout="sethide()"></d iv>
<script language="javascript">
if(document.layers)
{
mylayer = eval(document.list);
mylayer.captureEvents(Even t.MOUSEOUT | Event.MOUSEOVER)
mylayer.onmouseout = sethide;
mylayer.onmouseover = setshow;
}
</script>
</body>
</html>
<HTML>
<HEAD>
<TITLE>Drop Down Menu</TITLE>
<style type="text/css">
td {font-family:verdana, san-serif, arial;font-size:10pt;font-
.spcls {background:#EEEEEE;font-f
#list{position:absolute;z-
</style>
<script language="javascript">
showlist = false
timeoutID = ''
list = new Array()
list[0] = new Array('Option1_1','Option1
list[1] = new Array('Option2_1.','Option
list[2] = new Array('Option3_1.','Option
list[3] = new Array('Option4_1.','Option
listUrl = new Array()
listUrl[0] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list one
listUrl[1] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list two
listUrl[2] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list three
listUrl[3] = new Array('http://microsoft.com','http://microsoft.com','http://microsoft.com'); // URL for menu list four
function listme(val,divposition)
{
window.clearTimeout(timeou
bodystart = '<table border=1 >';
bodypart = '';
for(i=0; i< list[val].length; i++)
{
bodypart = bodypart + '<tr valign="top" align="center"><td><a href="'+listUrl[val][i]+'"
}
bodyend = '</table>';
if(document.all)
{
document.all.list.innerHTM
document.all.list.style.to
document.all.list.style.le
if(document.all.list.style
{
document.all.list.style.le
}
}
if(document.layers)
{
mylayer = eval(document.list);
mylayer.document.writeln(b
mylayer.moveTo(divposition
if(mylayer.pageX+mylayer.c
{
mylayer.moveTo(window.oute
}
mylayer.document.close();
}
timeoutID = window.setTimeout("deletem
}
function deleteme()
{
if(!showlist)
{
if(document.all)
{
document.all.list.innerHTM
document.all.list.style.to
document.all.list.style.le
}
if(document.layers)
{
mylayer = eval(document.list);
mylayer.document.write('')
mylayer.moveTo(0,40);
mylayer.document.close();
}
}
else
{
window.setTimeout("deletem
}
}
function returnback()
{
return;
}
function setshow()
{
showlist = true
}
function sethide()
{
showlist = false;
}
</script>
</HEAD>
<BODY >
<BR><BR><BR><BR><BR><BR><B
<table id="tbl" align="left" border="1" >
<tr valign="top" align="left">
<td><a href="javascript:listme(0,
<td><a href="javascript:listme(1,
<td><a href="javascript:listme(2,
<td><a href="javascript:listme(3,
</tr>
</table><br>
<div id="list" style="position:absolute;w
<script language="javascript">
if(document.layers)
{
mylayer = eval(document.list);
mylayer.captureEvents(Even
mylayer.onmouseout = sethide;
mylayer.onmouseover = setshow;
}
</script>
</body>
</html>
That is really ancient code. Do you realize that it will work only with IE and Netscrap4. Mozilla based browsers do not recognize document.all or document.layers. Your script is at least 5 years behind the browser technologes in use today.
Cd&
Cd&
ASKER
OK COBOLdino, I'm not in this full time - give me a direction to go in to get some better code. I did have this accomplished using a Fireworks created drop down only to find out the .js file was 20 pages long. I would like a drop down menu that appears on mouseover without 1000 lines of cryptic code doing magic for me in the background.
. . . and sean
When I change this part to relative- my drop down appears about 240 pixels away to the right - not right below:
<div id="list" style="position:relative;w idth:150" onmouseover="setshow()" onmouseout="sethide()"></d iv>
. . . and sean
When I change this part to relative- my drop down appears about 240 pixels away to the right - not right below:
<div id="list" style="position:relative;w
The 240 pixels is because your javascript was telling it to do that...
No matter, if you want state of the art code for creating a menu, I've posted an example for you.
http://www.pdgmedia.com/code/menus/cssmenu_full.html
Thanks,
Sean
No matter, if you want state of the art code for creating a menu, I've posted an example for you.
http://www.pdgmedia.com/code/menus/cssmenu_full.html
Thanks,
Sean
Its not complex for rudimentary modernization. you just need to use the document.getElementById() method for modern browsers.
If you duplicate the functions using document.all.list and use document.getElementById('l ist) the rest of the object references should work. The only other change would be to add a unit of measure to the style settings. Example:
if(document.document.getEl ementById)
{
document.getElementById('l ist').inne rHTML = ''
document.getElementById('l ist').styl e.top = 40+'px';
document.getElementById('l ist').styl e.left = 0+'px';
}
Probably not perfect, but just adding a couple of additional functions to use the DOM, will increase the cross-browser support.
If it was part of a larger migration to modern support, I would probably get rid of the NS4 stuff unless the server logs show visitors are actually using it. As long as it is doing the job you need done, there is no reason to fix what is not broken.
Cd&
If you duplicate the functions using document.all.list and use document.getElementById('l
if(document.document.getEl
{
document.getElementById('l
document.getElementById('l
document.getElementById('l
}
Probably not perfect, but just adding a couple of additional functions to use the DOM, will increase the cross-browser support.
If it was part of a larger migration to modern support, I would probably get rid of the NS4 stuff unless the server logs show visitors are actually using it. As long as it is doing the job you need done, there is no reason to fix what is not broken.
Cd&
ASKER
Sean,
Looks like some code that will work for me. I'm a little uncertain how to position the drop down always to the right. If I add a longer text line, it defaults to a drop down directly below - what I would like is to the right always.
<ul id="nav">
<li><a href="#"><nobr>Menu Link Menu Link </nobr></a>
Looks like some code that will work for me. I'm a little uncertain how to position the drop down always to the right. If I add a longer text line, it defaults to a drop down directly below - what I would like is to the right always.
<ul id="nav">
<li><a href="#"><nobr>Menu Link Menu Link </nobr></a>
Well, if I understand correctly, just add the following code to have the drop-down's display horizontally:
#nav li ul
{
position: absolute;
left: -999em;
/* set to the longest width */
width:600px;
}
#nav li ul li
{
display:inline;
}
#nav li ul li a
{
float:left;
}
Thanks,
Sean
#nav li ul
{
position: absolute;
left: -999em;
/* set to the longest width */
width:600px;
}
#nav li ul li
{
display:inline;
}
#nav li ul li a
{
float:left;
}
Thanks,
Sean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent Answer - Please tell me
1. Good reference that covers css positioning, i.e. this example
2. Have you embraced CSS totally and are now shunning tables in web page design?
1. Good reference that covers css positioning, i.e. this example
2. Have you embraced CSS totally and are now shunning tables in web page design?
1. Any content "below" the div will jump on the screen as the div becomes visible, because relative does take up document space.
2. "width:150" Be careful with these - all values need a measurement attached (150px) in browsers other than IE...
So, depending on you feel about # 1 will determine the outcome of the as yet unposted #3 :-)
Thanks,
Sean