Ho trovato il seguente menu pronto, e sono riuscito a modificarne le caratteristiche principali. Ora però ho un problema: non riesco a posizionarlo dove voglio! Siccome di quello che mi stampa JavaScript non ci ho capito nulla, mi potreste dare una dritta??? Grazie!
Parte 1
codice:
is = {};
is.agent = navigator.userAgent.toLowerCase();
is.ie4 = (is.agent.indexOf("msie 4") != -1);
is.ie5 = (is.agent.indexOf("msie 5") != -1);
is.ie55 = (is.agent.indexOf("msie 5.5") != -1);
is.ie6 = (is.agent.indexOf("msie 6") != -1);
is.ie7 = (is.agent.indexOf("msie 7") != -1);
is.ns4 = (is.agent.indexOf("4") != -1 && document.layers);
is.ns6 = (is.agent.indexOf("netscape6") != -1 && is.agent.indexOf("6.1") == -1);
is.ns61 = (is.agent.indexOf("netscape6/6.1") != -1);
is.ns6x = (is.agent.indexOf("netscape6") != -1);
is.ie = (is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ie7);
is.moz = (is.agent.indexOf("gecko")!= -1);
is.mac = (is.agent.indexOf("mac") != -1);
is.win = (is.agent.indexOf("win") != -1);
is.iestrict = (is.win && is.ie6 && is.ie7 && document.compatMode == "CSS1Compat");
is.macstrict = (is.ie5 && is.mac && document.doctype && document.doctype.name.indexOf(".dtd") != -1);
is.strict = (is.iestrict || is.macstrict);
is.dom = (is.ie5 || is.ie55 || is.ie6 || is.ie7 || is.ns6x || is.moz);
var css_px = (is.ns4) ?"" : "px";
function menuObj(obj, par, nst) {
page = new Object();
page.width = (is.ns6 || is.ns61 || is.ns6 || is.ns4 || is.moz) ? innerWidth : document.body.clientWidth;
page.height = (is.ns6 || is.ns61 || is.ns6 || is.ns4 || is.moz) ? innerHeight : document.body.clientHeight;
if(!is.ns4) this.lyr = (is.dom) ?document.getElementById(obj) : document.all[obj];
else this.lyr = (!nst) ?document.layers[obj] : document.layers[nst].document.layers[obj];
this.sty = (!is.ns4) ? this.lyr.style : this.lyr;
if(par) this.parent = par;
this.obj = obj + "SwipeLayer";
eval(this.obj + "= this");
}
menuObj.prototype.timer = null;
menuObj.prototype.wipe = 0;
menuObj.prototype.offX = Function('oX = (is.ie || is.ns61 || is.moz) ?this.lyr.offsetLeft : parseInt(this.sty.left);return oX');
menuObj.prototype.offY = Function('oY = (is.ie || is.ns61 ||is.moz) ?this.lyr.offsetTop : parseInt(this.sty.top);return oY;');
menuObj.prototype.offW = Function('oW = (!is.ns4) ?this.lyr.offsetWidth : this.lyr.clip.width; return oW;')
menuObj.prototype.offH = Function('oH = (!is.ns4) ?this.lyr.offsetHeight : this.lyr.clip.height; return oH;')
menuObj.prototype.maxWipe = function() {
if(is.dom) return this.offH()+10;
if(is.ns4) return (sAtt.height*this.lyr.document.layers.length)+10;
}
wipeMenu.prototype.addMain = function(name, hasSub, txt, url) {
menuName = this.name;
wipePos = this.pos;
mAtt = this.mAtt, sAtt = this.sAtt;
if(this.main[name]) return;
if(is.ns4) {
var mainMenu = new Layer(mAtt.width);
var styStr = "text-decoration:none; color:"+mAtt.fg_off+"; padding:"+((mAtt.height/2)-(mAtt.font_size/2)-1)+"px 0px 0px 0px; font-size:"+mAtt.font_size+"px; font-family:"+mAtt.font+";"
var pd = "padding:0px 6px 0px 6px;"
mainMenu.document.write('<div align="'+mAtt.align+'" style="'+pd+'">'+txt+'</div>');
mainMenu.document.close();
mainMenu.captureEvents(Event.MOUSEUP);
mainMenu.resizeTo(mAtt.width,mAtt.height)
if(mAtt.bg_off.indexOf("url") != -1) {
mainMenu.background.src = mAtt.bg_off.substring(4,mAtt.bg_off.length-1);
mainMenu.background.src = mAtt.bg_off.substring(4,mAtt.bg_off.length-1);
} else mainMenu.bgColor = mAtt.bg_off;
mainMenu.visibility = "visible";
}
if(is.dom) {
var mainMenu = document.createElement("DIV");
var pf = Math.ceil(((mAtt.height-mAtt.font_size)/2)-2); var wf = (is.ns6x || is.strict) ?12 : 0;
var pf2 = (mAtt.height%2 == 0) ?1 : 0;
mainMenu.innerHTML = txt;
mainMenu.id = name+menuName;
var styStr = "position:absolute; width:"+(mAtt.width-wf)+"px; border:solid "+mAtt.border+"px "+mAtt.border_color+"; color:"+mAtt.fg_off+"; text-align:"+mAtt.align+"; font-size:"+mAtt.font_size+"px; font-family:"+mAtt.font+"; padding:"+pf+"px 6px "+(pf+pf2)+"px 6px; background:"+mAtt.bg_off+"; cursor:pointer; cursor:hand;"
mainMenu.style.cssText = styStr;
mainMenu.setAttribute("style", styStr);
document.body.appendChild(mainMenu);
}
if(is.ie4) {
var pf = Math.ceil(((mAtt.height-mAtt.font_size)/2)-2);
var pf2 = (mAtt.height%2 == 0) ?1 : 0;
alert(pf+pf2)
var styStr = "position:absolute; width:"+(mAtt.width)+"px; border:solid "+mAtt.border+"px "+mAtt.border_color+"; color:"+mAtt.fg_off+"; text-align:"+mAtt.align+"; font-size:"+mAtt.font_size+"px; font-family:"+mAtt.font+"; padding:"+(pf)+"px 6px "+(pf)+"px 6px; background:"+mAtt.bg_off+"; cursor:hand;"
var mM = '<div id="'+name+menuName+'" style="'+styStr+'">'+txt+'</div>';
document.body.insertAdjacentHTML("beforeEnd", mM);
var mainMenu = document.all[name+menuName];
}
mainMenu.onmouseover = Function('if('+hasSub+')'+menuName+'.subs["'+name+'"].show("'+wipePos+'");over_out(this, "'+mAtt.bg_on+'", "'+mAtt.fg_on+'")')
mainMenu.onmouseout = Function('if('+hasSub+')'+menuName+'.subs["'+name+'"].hide();over_out(this, "'+mAtt.bg_off+'", "'+mAtt.fg_off+'");')
mainMenu.onmousedown = Function('location.href = "'+url+'"');
this.main[name] = new menuObj(mainMenu.id);
this.mainNum[this.mainNum.length] = this.main[name];
if(!hasSub) return;
if(is.ns4) {
var subC = new Layer(sAtt.width);
subC.resizeTo(sAtt.width,0);
subC.visibility = "hidden";
}
if(is.dom) {
var subC = document.createElement("DIV");
subC.id = name+menuName+"Sub";
var wf = (is.ns6x) ?4 : 0;
var styStr = "position:absolute; visibility:hidden; clip:rect(0px "+(sAtt.width+20)+"px 0px 0px); border:solid 1px "+sAtt.border_color+"; border-width:"+sAtt.border+"px 0px 0px 0px; cursor:default;"
subC.style.cssText = styStr;
subC.setAttribute("style", styStr);
document.body.appendChild(subC);
}
if(is.ie4) {
var styStr = "position:absolute; visibility:hidden; clip:rect(0px "+(sAtt.width+20)+"px 0px 0px); border:solid 1px "+sAtt.border_color+"; border-width:"+sAtt.border+"px 0px 0px 0px; cursor:default;"
var sC = '<div id="'+name+menuName+'Sub" style="'+styStr+'"></div>';
document.body.insertAdjacentHTML("beforeEnd", sC);
var subC = document.all[name+menuName+"Sub"];
}
this.subs[name] = new menuObj(subC.id, this.main[name]);
subC.onmouseover = Function(menuName+'.subs["'+name+'"].show("'+wipePos+'");');
subC.onmouseout = Function(menuName+'.subs["'+name+'"].hide();');
}