ConfusedOfLife
11-25-2002, 08:39 AM
Here's the code, I ask my question in the nex post! ( too much characters to write! ) :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style>
/* This class is used for the title */
.Title
{
color : white;
background-color : black;
font: 22px Tahoma;
width : 150px;
border : thin groove #3b3b3b;
cursor : hand;
}
/* This is the place that you can change
the shape of your menu items
*/
.Items
{
color : white;
background-color : #828282;
font: 18px Tahoma;
text-decoration : none;
width : 150px;
border-bottom : thin groove #3b3b3b;
border-left : thin groove #3b3b3b;
border-right : thin groove #3b3b3b;
cursor : hand;
}
</style>
</head>
<body>
<script>
GLOBAL_ARRAY = new Array();
function makeMenu( parentId, objId, Title, menuArray, Speed)
{
var mainDiv = document.createElement("div");
mainDiv.setAttribute( "id", objId);
mainDiv.onmouseout = function()
{
hideIt( "inner" + objId, Speed);
}
// Putting the menu inside the id of another tag if it's
// supported
if ( parentId == "" )
document.body.appendChild(mainDiv);
else
document.getElementById( parentId).appendChild( mainDiv);
// Creating the title;
var mainTitle = document.createElement("span");
mainTitle.className = "Title";
mainDiv.appendChild(mainTitle);
mainTitle.innerHTML = "<center>" + Title + "</center>";
// Creating the action when the mouse pointer goes on
// the title!
mainTitle.onmouseover = function()
{
showIt( "inner" + objId, Speed);
}
// Putting a break between the title and the menu items!
var br = document.createElement("br");
mainDiv.appendChild(br);
var innerDiv = document.createElement( "div");
innerDiv.setAttribute("id", "inner" + objId);
innerDiv.style.position = "absolute";
innerDiv.onmouseover = function()
{
showIt( "inner" + objId, Speed);
}
// This is a dummy number that later we be able to get
// the clientHeight of the innerDiv.
innerDiv.style.height = 10;
// Clipping our innerDiv to zero! Invisible somehow!!
innerDiv.style.clip = "rect(0px 150px 0px 0px)";
mainDiv.appendChild( innerDiv);
for (i=0; i<menuArray.length; i++)
{
var item = document.createElement("div");
item.className = "Items";
item.onmouseover = function()
{
this.style.backgroundColor = "#4c4c4c";
};
item.onmouseout = function()
{
this.style.backgroundColor = "#828282";
};
item.onclick = function()
{
// The redirection should occur in here, but
// I didn't write this part yet, I have another
// question regarding to this part that I'll
// ask later!
}
item.innerHTML = "<center>" + menuArray[i][0] + "</center>";
innerDiv.appendChild(item);
}
}
function showIt( childId, Speed)
{
clearTimeout( GLOBAL_ARRAY[childId,"hide"]);
var obj = ( document.getElementById) ? ( document.getElementById( childId)) : ( document.all.childId);
var maxHeight = obj.clientHeight;
var clipHeight = parseInt(obj.style.clip.split("rect(0px 150px ")[1].split("px 0px)")[0]);
if ( clipHeight < maxHeight )
{
obj.style.clip = "rect(0px 150px " + ( clipHeight + 2) + "px 0px)";
// Simulating a kind of f*cking associative array!
// Why doesn't really javascript support associative arrays?!
GLOBAL_ARRAY[childId,"value"] = childId;
GLOBAL_ARRAY[childId,"speed"] = Speed;
GLOBAL_ARRAY[childId,"show"] = setTimeout
("showIt(GLOBAL_ARRAY[" + childId + ",'value'], GLOBAL_ARRAY[" + childId + ",'speed'])", Speed);
}
else
// When the whole menu is opened and mouse pointer is going from an element
// to another element, in the gap between these 2 elements the onmouseover
// triggers and hideIt tries to close the menu, but since the mouse is fast
// and goes to the next item immediately ( doesn't stop on the gap ), the showIt
// gets activated again and prevents the hideIt to function, but we can
// see a flickering in the end of the menu, it's because hideIt() clips
// two pixels and showIt immediately bring those pixels back, to prevent
// this, in the end of showIt ( when the whole menu is on the screen ),
// I add 2 pixels to the end of it that hideIt hides them first and
// then goes to the real menu if mouse is really out of the menu.
obj.style.clip = "rect(0px 150px " + ( clipHeight + 2) + "px 0px)";
}
function hideIt( childId, Speed)
{
clearTimeout( GLOBAL_ARRAY[childId,"show"]);
var obj = ( document.getElementById) ? ( document.getElementById( childId)) : ( document.all.childId);
var maxHeight = obj.clientHeight;
var clipHeight = parseInt(obj.style.clip.split("rect(0px 150px ")[1].split("px 0px)")[0]);
if ( clipHeight > 0 )
{
obj.style.clip = "rect(0px 150px " + ( clipHeight - 2) + "px 0px)";
clearTimeout( GLOBAL_ARRAY[childId,"show"]);
GLOBAL_ARRAY[childId,"hide"] = setTimeout
("hideIt(GLOBAL_ARRAY[" + childId + ",'value'], GLOBAL_ARRAY[" + childId + ",'speed'])", Speed);
}
}
</script>
<table border="0">
<tr>
<td id="parent#1">
</td>
<td id="parent#2">
</td>
<td id="parent#3">
</td>
<td id="parent#4">
</td>
<td id="parent#5">
</td>
<td id="parent#6">
</td>
</tr>
</table>
<script>
menuArr1 =[
[ "First" , "http://www.somewhere.com"],
[ "Second" , "http://www.somewhere.com"],
[ "Third" , "http://www.somewhere.com"],
[ "Fourth" , "http://www.somewhere.com"],
[ "Fifth" , "http://www.somewhere.com"],
[ "Sixth" , "http://www.somewhere.com"]
];
menuArr2 =[
[ " 1 " , "http://www.Oopse.com"],
[ " 2 " , "http://www.Oopse.com"],
[ " 3 " , "http://www.Oopse.com"],
[ " 4 " , "http://www.Oopse.com"],
[ " 5 " , "http://www.Oopse.com"],
[ " 6 " , "http://www.Oopse.com"],
[ " 7 " , "http://www.Oopse.com"],
[ " 8 " , "http://www.Oopse.com"],
[ " 9 " , "http://www.Oopse.com"],
[ " 10 " , "http://www.Oopse.com"],
[ " 11 " , "http://www.Oopse.com"],
[ " 12 " , "http://www.Oopse.com"],
[ " 13 " , "http://www.Oopse.com"],
[ " 14 " , "http://www.Oopse.com"],
[ " 15 " , "http://www.Oopse.com"],
[ " 16 " , "http://www.Oopse.com"]
];
makeMenu("parent#1", "1stMenuId", "Menu #1", menuArr1, 15);
makeMenu("parent#2", "2ndMenuId", "Menu #2", menuArr2, 1);
makeMenu("parent#3", "3rdMenuId", "Menu #3", menuArr1, 7);
makeMenu("parent#4", "4thMenuId", "Menu #4", menuArr2, 10);
makeMenu("parent#5", "5thMenuId", "Menu #5", menuArr1, 5);
makeMenu("parent#6", "6thMenuId", "Menu #6", menuArr2, 2);
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style>
/* This class is used for the title */
.Title
{
color : white;
background-color : black;
font: 22px Tahoma;
width : 150px;
border : thin groove #3b3b3b;
cursor : hand;
}
/* This is the place that you can change
the shape of your menu items
*/
.Items
{
color : white;
background-color : #828282;
font: 18px Tahoma;
text-decoration : none;
width : 150px;
border-bottom : thin groove #3b3b3b;
border-left : thin groove #3b3b3b;
border-right : thin groove #3b3b3b;
cursor : hand;
}
</style>
</head>
<body>
<script>
GLOBAL_ARRAY = new Array();
function makeMenu( parentId, objId, Title, menuArray, Speed)
{
var mainDiv = document.createElement("div");
mainDiv.setAttribute( "id", objId);
mainDiv.onmouseout = function()
{
hideIt( "inner" + objId, Speed);
}
// Putting the menu inside the id of another tag if it's
// supported
if ( parentId == "" )
document.body.appendChild(mainDiv);
else
document.getElementById( parentId).appendChild( mainDiv);
// Creating the title;
var mainTitle = document.createElement("span");
mainTitle.className = "Title";
mainDiv.appendChild(mainTitle);
mainTitle.innerHTML = "<center>" + Title + "</center>";
// Creating the action when the mouse pointer goes on
// the title!
mainTitle.onmouseover = function()
{
showIt( "inner" + objId, Speed);
}
// Putting a break between the title and the menu items!
var br = document.createElement("br");
mainDiv.appendChild(br);
var innerDiv = document.createElement( "div");
innerDiv.setAttribute("id", "inner" + objId);
innerDiv.style.position = "absolute";
innerDiv.onmouseover = function()
{
showIt( "inner" + objId, Speed);
}
// This is a dummy number that later we be able to get
// the clientHeight of the innerDiv.
innerDiv.style.height = 10;
// Clipping our innerDiv to zero! Invisible somehow!!
innerDiv.style.clip = "rect(0px 150px 0px 0px)";
mainDiv.appendChild( innerDiv);
for (i=0; i<menuArray.length; i++)
{
var item = document.createElement("div");
item.className = "Items";
item.onmouseover = function()
{
this.style.backgroundColor = "#4c4c4c";
};
item.onmouseout = function()
{
this.style.backgroundColor = "#828282";
};
item.onclick = function()
{
// The redirection should occur in here, but
// I didn't write this part yet, I have another
// question regarding to this part that I'll
// ask later!
}
item.innerHTML = "<center>" + menuArray[i][0] + "</center>";
innerDiv.appendChild(item);
}
}
function showIt( childId, Speed)
{
clearTimeout( GLOBAL_ARRAY[childId,"hide"]);
var obj = ( document.getElementById) ? ( document.getElementById( childId)) : ( document.all.childId);
var maxHeight = obj.clientHeight;
var clipHeight = parseInt(obj.style.clip.split("rect(0px 150px ")[1].split("px 0px)")[0]);
if ( clipHeight < maxHeight )
{
obj.style.clip = "rect(0px 150px " + ( clipHeight + 2) + "px 0px)";
// Simulating a kind of f*cking associative array!
// Why doesn't really javascript support associative arrays?!
GLOBAL_ARRAY[childId,"value"] = childId;
GLOBAL_ARRAY[childId,"speed"] = Speed;
GLOBAL_ARRAY[childId,"show"] = setTimeout
("showIt(GLOBAL_ARRAY[" + childId + ",'value'], GLOBAL_ARRAY[" + childId + ",'speed'])", Speed);
}
else
// When the whole menu is opened and mouse pointer is going from an element
// to another element, in the gap between these 2 elements the onmouseover
// triggers and hideIt tries to close the menu, but since the mouse is fast
// and goes to the next item immediately ( doesn't stop on the gap ), the showIt
// gets activated again and prevents the hideIt to function, but we can
// see a flickering in the end of the menu, it's because hideIt() clips
// two pixels and showIt immediately bring those pixels back, to prevent
// this, in the end of showIt ( when the whole menu is on the screen ),
// I add 2 pixels to the end of it that hideIt hides them first and
// then goes to the real menu if mouse is really out of the menu.
obj.style.clip = "rect(0px 150px " + ( clipHeight + 2) + "px 0px)";
}
function hideIt( childId, Speed)
{
clearTimeout( GLOBAL_ARRAY[childId,"show"]);
var obj = ( document.getElementById) ? ( document.getElementById( childId)) : ( document.all.childId);
var maxHeight = obj.clientHeight;
var clipHeight = parseInt(obj.style.clip.split("rect(0px 150px ")[1].split("px 0px)")[0]);
if ( clipHeight > 0 )
{
obj.style.clip = "rect(0px 150px " + ( clipHeight - 2) + "px 0px)";
clearTimeout( GLOBAL_ARRAY[childId,"show"]);
GLOBAL_ARRAY[childId,"hide"] = setTimeout
("hideIt(GLOBAL_ARRAY[" + childId + ",'value'], GLOBAL_ARRAY[" + childId + ",'speed'])", Speed);
}
}
</script>
<table border="0">
<tr>
<td id="parent#1">
</td>
<td id="parent#2">
</td>
<td id="parent#3">
</td>
<td id="parent#4">
</td>
<td id="parent#5">
</td>
<td id="parent#6">
</td>
</tr>
</table>
<script>
menuArr1 =[
[ "First" , "http://www.somewhere.com"],
[ "Second" , "http://www.somewhere.com"],
[ "Third" , "http://www.somewhere.com"],
[ "Fourth" , "http://www.somewhere.com"],
[ "Fifth" , "http://www.somewhere.com"],
[ "Sixth" , "http://www.somewhere.com"]
];
menuArr2 =[
[ " 1 " , "http://www.Oopse.com"],
[ " 2 " , "http://www.Oopse.com"],
[ " 3 " , "http://www.Oopse.com"],
[ " 4 " , "http://www.Oopse.com"],
[ " 5 " , "http://www.Oopse.com"],
[ " 6 " , "http://www.Oopse.com"],
[ " 7 " , "http://www.Oopse.com"],
[ " 8 " , "http://www.Oopse.com"],
[ " 9 " , "http://www.Oopse.com"],
[ " 10 " , "http://www.Oopse.com"],
[ " 11 " , "http://www.Oopse.com"],
[ " 12 " , "http://www.Oopse.com"],
[ " 13 " , "http://www.Oopse.com"],
[ " 14 " , "http://www.Oopse.com"],
[ " 15 " , "http://www.Oopse.com"],
[ " 16 " , "http://www.Oopse.com"]
];
makeMenu("parent#1", "1stMenuId", "Menu #1", menuArr1, 15);
makeMenu("parent#2", "2ndMenuId", "Menu #2", menuArr2, 1);
makeMenu("parent#3", "3rdMenuId", "Menu #3", menuArr1, 7);
makeMenu("parent#4", "4thMenuId", "Menu #4", menuArr2, 10);
makeMenu("parent#5", "5thMenuId", "Menu #5", menuArr1, 5);
makeMenu("parent#6", "6thMenuId", "Menu #6", menuArr2, 2);
</script>
</body>
</html>