Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu drop-down after link - how about under link?

Status
Not open for further replies.

Medar

MIS
Apr 2, 2001
2
US
I have a script I am using that will drop a menu after a link you click. I am trying to modify it where it will actually drop it directly BELOW the link instead. <br> would not work because I can place this menu on any word in a paragraph, and it does not disrupt the flow of the paragraph (the menu opens over the page).

Any quick fixes to this? Thanks in advance, I am tinkering but having no luck.

The code is as follows, rather simple:

<a href=&quot;&quot; onclick=&quot;Medar_menu.style.visibility = (Medar_menu.style.visibility=='visible' ? 'hidden' : 'visible'); return false;&quot; onmouseout=&quot;if (window.event.clientX<=Medar_menu.offsetLeft || window.event.clientY<=Medar_menu.offsetTop) { Medar_menu.style.visibility = 'hidden'; }&quot;>
Test Menu!
</a>
<span id=&quot;Medar_menu&quot; class=&quot;navSubmenu&quot; onmouseover=&quot;this.style.visibility='visible';&quot; onmouseout=&quot;this.style.visibility='hidden';&quot;>

<a class=&quot;navSubmenuLink&quot; href=&quot; target=&quot;_parent&quot;> • Link 1</a><br>
<a class=&quot;navSubmenuLink&quot; href=&quot; target=&quot;_parent&quot;> • Link 2</a><br>
<a class=&quot;navSubmenuLink&quot; href=&quot; target=&quot;_parent&quot;> • Link 3</a><br>

</span>
 
Use position:absolute in the style of the menu then position it at the coorinates of the lower left corner of the link. Here's an example:

<html>
<head>
<script>
function dropMenu(x,y){
m=document.getElementById(&quot;menu&quot;);
m.style.left=x;
m.style.top=y;
m.style.display='block';
}
function hideMenu(){
document.getElementById(&quot;menu&quot;).style.display='none';
}
</script>
</head>
<body>
<div id=&quot;menu&quot; style=&quot;position:absolute;display:none;background-color:#CCCCCC;width:200px;height:150px;text-align:right&quot;>
<a href=&quot;javascript:hideMenu()&quot;>X</a>
</div>

<span onclick=&quot;dropMenu(this.offsetLeft,this.offsetTop+this.offsetHeight)&quot; style=&quot;border:solid red 1px&quot;>Click Me</span>

<span onclick=&quot;dropMenu(this.offsetLeft,this.offsetTop+this.offsetHeight)&quot; style=&quot;position:relative;left:100px;top:200px;border:solid red 1px&quot;>Click Me</span>


Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top