Riposto il codice del mio script con alcune nuove modifiche!
codice:
<html>
<head>
<title>Menu</title>
</head>
<body>
<script type="text/javascript">
<!--
var voceMenu=new Array();
voceMenu[0]=["Home page","./index.htm"];
voceMenu[1]=["Forum","./forum.htm"];
voceMenu[2]=["Mailing list","./mailing.htm"];
voceMenu[3]=["Javascript","./javascript.htm"];
voceMenu[4]=["Applet Java","./applet.htm"];
voceMenu[5]=["Sondaggi","./sondaggi.htm"];
var oggettoMenu=new Array();
var altezza=23;
var altezzaContenuto=27;
var larghezza=100;
var id_contenitore="contenitore";
// metodo vaiURL
function vaiURL() {
window.location.href=this.URL;
};
// metodo decolora
function decolora() {
document.getElementById(this.nomeOggettoHTML).style.backgroundColor="pink";
};
// metodo getLeft
function getLeft() {
var getLeft=parseInt(document.getElementById(this.nomeOggettoHTML).style.left);
return getLeft;
};
// metodo mouseOver
function mouseOver() {
if(eval("window."+this.nomeOggetto+".timer")) clearTimeout(this.timer);
document.getElementById(this.nomeOggettoHTML).style.backgroundColor="orange";
document.getElementById(this.nomeOggettoHTML).style.left="40px";
};
// metodo mouseOut
function mouseOut() {
if(this.getLeft()>0) {
document.getElementById(this.nomeOggettoHTML).style.left=this.getLeft()-1;
}
else {
clearTimeout(this.timer);
};
this.timer=window.setTimeout(this.nomeOggetto+".mouseOut();",20);
};
// classe Menu
function Menu(numeroArray) {
this.nomeOggetto="oggettoMenu["+numeroArray+"]";
this.nomeOggettoHTML="subMenu"+numeroArray;
this.numeroArray=numeroArray;
this.testo=voceMenu[this.numeroArray][0];
this.URL=voceMenu[this.numeroArray][1];
this.timer=null;
this.mouseOver=mouseOver;
this.mouseOut=mouseOut;
this.decolora=decolora;
this.vaiURL=vaiURL;
};
// funzione costruzioneSubMenu
function costruzioneSubMenu() {
for(var x=0; x<voceMenu.length; x++) {
document.getElementById(id_contenitore).innerHTML+="<div style=\"position:absolute; top:"+(oggettoMenu[x].numeroArray*altezzaContenuto)+"px; left:0px; width:100px; height:"+altezzaContenuto+"px; border:#000000 0px solid; cursor:hand\" onmouseover=\""+oggettoMenu[x].nomeOggetto+".mouseOver();\" onmouseout=\""+oggettoMenu[x].nomeOggetto+".decolora(); "+oggettoMenu[x].nomeOggetto+".mouseOut();\" onclick=\""+oggettoMenu[x].nomeOggetto+".vaiURL();\"><div id=\""+oggettoMenu[x].nomeOggettoHTML+"\" style=\"position:absolute; top:0px; left:0px; width:100px; height:"+altezza+"px; background-color:pink; border:#ffffff 1px outset\">"+oggettoMenu[x].testo+"</div>";
oggettoMenu[x].getLeft=getLeft;
};
};
// funzione inizia
function inizia() {
for(var x=0; x<voceMenu.length; x++) oggettoMenu[x]=new Menu(x);
costruzioneSubMenu();
};
// funzione all'avvio
window.onload=inizia;
// costruzione contenitore
document.write("<div id=\""+id_contenitore+"\" style=\"position:absolute; top:20px; left:20px; border:#000000 0px solid; width:250px; height:250px; color:#ffffff; font:bold 1pc arial; text-align:center\"> </div>");
//-->
</script>
</body>
</html>