splanton
asked on
Need to reposition <UL> element with javascript.
I am modifying a natty piece of javascript code I have for menus. I am trying to expand it to meet a clients requirements.
The test set for this is as follows:
As you can see, I am trying to add image elements to the menu. Part of the requirement is that the 'popup' be left justified to the top level <ul> tag (with id= 'menu'). As you can see from my example the 'popup' currently appears nested (and ot surprisingly) within it's parent <li> tag.
There does not seem to be a clean CSS solution to this so I am looking at the javascript. As far as I can see there is the possibility within the 'dd.prototype.st=function( x,f){' to dynamically alter the position by identifying the parent id of 'menu' and offestting the position of the element being 'poped up' accordingly?
The problem is I have a basic understanding of what is going on but not enough to take it apart and create a robust solution. I am now out of my depth.
I understand that I could re-invent the whole thing in jquery, but as i have 99% of the functionality already working it seems a bit daft not to try and mod the existing code?
I don't mind changing the HTML code to facilitate a simpler solution of that is recomended.
Thanks in advance. :)
The test set for this is as follows:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.menumain {background-color: #156ab9;float: left;width: 984px;margin: 10px 0px 0px 0px;}
ul.menu {list-style:none; margin:0; padding:0;}
ul.menu a {display:block; color:#fff; text-decoration:none}
ul.menu li {position:relative; float:left;}
ul.menu ul {margin:0; padding:0;position:absolute; top:35px; left:0px; background:#7c6475;display:none; opacity:0; list-style:none; width:940px;}
ul.menu ul li {position:relative; float:left; width:280px; margin:10px 10px 10px 10px;}
ul.menu ul li a {display:block; padding:5px 7px 5px 10px; background-color: #eeeeee;color: #FFFFFF;}
ul.menu ul li a:hover {background-color: #125ca0;}
ul.menu .menulink {padding:10px 5px 10px 10px; font-weight:bold; font-size: 14px;}
ul.menu .menulink:hover, ul.menu .menuhover {background-color: #FFFFFF;color: #999999;}
ul.menu .area1 {width: 100px;height:100px;float:left;background-color: #ff0000;margin: 10px 0px 10px 20px;}
ul.menu .area2 {width: 100px;height:100px;float:right;background-color: #ff0000;margin: 10px 20px 0px 0px;}
ul.menu .area3 {width: 300px;float:left;background-color: #ff0000;margin: 10px 0px 0px 20px;}
</style>
<script type="text/javascript">
var menu=function(){
var t=5,z=50,s=10,a;
function dd(n){this.n=n; this.h=[]; this.c=[]}
dd.prototype.init=function(p,c){
a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
for(i;i<l;i++){
var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
h.onmouseover=new Function(this.n+'.st('+i+',true)');
h.onmouseout=new Function(this.n+'.st('+i+')');
}
}
dd.prototype.st=function(x,f){
var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
clearInterval(c.t); c.style.overflow='hidden';
if(f){
p.className+=' '+a;
if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
if(c.mh==c.offsetHeight){c.style.overflow='visible'}
else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
}
function sl(c,f){
var h=c.offsetHeight;
if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
clearInterval(c.t); return
}
var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
c.style.height=h+(d*f)+'px'
}
return{dd:dd}
}(); </script>
</head>
<div class="menumain">
<ul class="menu" id="menu">
<li><a href="#" class="menulink">Home</a>
<ul>
<div class="area1">image #1 goes here</div>
<div class="area2">image #2 goes here</div>
<div class="area3">
<li><a href="#" class="topline">Commercial Waste</a></li>
<li><a href="#">Contract Waste</a></li>
</div>
</ul>
</li>
<li><a href="#" class="menulink">Profile</a>
<ul>
<div class="area1">image #1 goes here</div>
<div class="area2">image #2 goes here</div>
<div class="area3">
<li><a href="#" class="topline">Commercial Waste</a></li>
<li><a href="#">Contract Waste</a></li>
</div>
</ul>
</li>
<li><a href="#" class="menulink">Tournaments</a>
<ul>
<div class="area1">image #1 goes here</div>
<div class="area2">image #2 goes here</div>
<div class="area3">
<li><a href="#" class="topline">Commercial Waste</a></li>
<li><a href="#">Contract Waste</a></li>
</div>
</ul>
</li>
</ul>
<script type="text/javascript">
var menu=new menu.dd("menu");
menu.init("menu","menuhover");
</script>
</div>
<Div style="float:left; width:500px;height:1000px;background-color: #e3990b;"
<body>
</body>
</html>
As you can see, I am trying to add image elements to the menu. Part of the requirement is that the 'popup' be left justified to the top level <ul> tag (with id= 'menu'). As you can see from my example the 'popup' currently appears nested (and ot surprisingly) within it's parent <li> tag.
There does not seem to be a clean CSS solution to this so I am looking at the javascript. As far as I can see there is the possibility within the 'dd.prototype.st=function(
The problem is I have a basic understanding of what is going on but not enough to take it apart and create a robust solution. I am now out of my depth.
I understand that I could re-invent the whole thing in jquery, but as i have 99% of the functionality already working it seems a bit daft not to try and mod the existing code?
I don't mind changing the HTML code to facilitate a simpler solution of that is recomended.
Thanks in advance. :)
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.