Jeg er igang med at lave en hjemmeside for nogen. I den forbindelse har jeg fundet en dropdown-menu, som virker fint nok, men desværre lukker den helt sammen hver gang man klikker på et link, så siden loader igen. Derfor vil jeg høre om der er nogen der ved hvordan man kan få den til at åbne den sidst åbne undermenu automatisk når en side loader.
Scriptet som jeg bruger ser således ud:
/************************************************************************************
This script is a "foldout" menu script, all the "foldouts" will
stay outfolded in older browsers.
To change where the menu appears change the left and top values of the divCont
in the stylesheets, it's currently placed relative so you can
place this menu in tables or similar if you want. Change the
text colors and size in the A.clMain and A.clSubb classes.
************************************************************************************/
/************************************************************************************
Change this to false if you want all the submenus to get unfold when you
foldout a new one.
************************************************************************************/
var stayFolded=false
/************************************************************************************
Browsercheck
************************************************************************************/
var n = (document.layers) ? 1:0;
var ie = (document.all) ? 1:0;
var browser=((n || ie) && parseInt(navigator.appVersion)>=4)
/************************************************************************************
Making cross-browser objects
************************************************************************************/
function makeMenu(obj,nest){
nest=(!nest) ? '':'document.'+nest+'.'
this.css=(n) ? eval(nest+'document.'+obj):eval('document.all.'+obj+'.style')
this.ref=(n) ? eval(nest+'document.'+obj+'.document'):eval('document');
this.height=n?this.ref.height:eval(obj+'.offsetHeight')
this.x=(n)? this.css.left:this.css.pixelLeft;this.y=(n)? this.css.top:this.css.pixelTop;
this.hideIt=b_hideIt; this.showIt=b_showIt; this.vis=b_vis; this.moveIt=b_moveIt
return this
}
function b_showIt(){this.css.visibility="visible"}
function b_hideIt(){this.css.visibility="hidden"}
function b_vis(){if(this.css.visibility=="hidden" || this.css.visibility=="hide") return true;}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x; this.css.top=this.y}
/************************************************************************************
Initiating the page. Just add to the arrays here to get more menuitems
and add divs in the page
************************************************************************************/
function init(){
oTop=new Array()
oTop[10]=new makeMenu('divTop1','divCont')
oTop[1]=new makeMenu('divTop2','divCont')
oTop[2]=new makeMenu('divTop3','divCont')
oTop[3]=new makeMenu('divTop4','divCont')
oTop[4]=new makeMenu('divTop5','divCont')
oTop[5]=new makeMenu('divTop6','divCont')
oTop[6]=new makeMenu('divTop7','divCont')
oTop[7]=new makeMenu('divTop8','divCont')
oTop[8]=new makeMenu('divTop9','divCont')
oTop[9]=new makeMenu('divTop10','divCont')
oTop[0]=new makeMenu('divTop11','divCont')
oSub=new Array()
oSub[10]=new makeMenu('divSub1','divCont.document.divTop1')
oSub[1]=new makeMenu('divSub2','divCont.document.divTop2')
oSub[2]=new makeMenu('divSub3','divCont.document.divTop3')
oSub[3]=new makeMenu('divSub4','divCont.document.divTop4')
oSub[4]=new makeMenu('divSub5','divCont.document.divTop5')
oSub[5]=new makeMenu('divSub6','divCont.document.divTop6')
oSub[6]=new makeMenu('divSub7','divCont.document.divTop7')
oSub[7]=new makeMenu('divSub8','divCont.document.divTop8')
oSub[8]=new makeMenu('divSub9','divCont.document.divTop9')
oSub[9]=new makeMenu('divSub10','divCont.document.divTop10')
oSub[0]=new makeMenu('divSub11','divCont.document.divTop11')
for(i=0;i<oSub.length;i++){ oSub[i].hideIt() }
for(i=1;i<oTop.length;i++){ oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height) }
}
/************************************************************************************
This is the function that changes the sub menus to folded or unfolded state.
************************************************************************************/
function menu(num){
if(browser){
if(!stayFolded){
for(i=0;i<oSub.length;i++){
if(i!=num) oSub[i].hideIt()
}
for(i=1;i<oTop.length;i++){
oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
}
}
oSub[num].vis()?oSub[num].showIt():oSub[num].hideIt()
for(i=1;i<oTop.length;i++){
if(!oSub[i-1].vis()) oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height+oSub[i-1].height)
else oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
}
}
}
Her er et lille uddrag af menu.php, som includeres der hvor menuerne skal være:
<div id="divTop2" class="clTop"><a href="#" onclick="menu(1); return false" class="clMain">Historie</a>
<div id="divSub2" class="clSub">
<a href="<?=$_SERVER['PHP_SELF']."?kat=2&sub=1&menu=1"; ?>" class="clSubb">- Ikast Kirke</a>
<a href="<?=$_SERVER['PHP_SELF']."?kat=2&sub=2&menu=1"; ?>" class="clSubb">- Østre Kapel</a>
<a href="<?=$_SERVER['PHP_SELF']."?kat=2&sub=3&menu=1"; ?>" class="clSubb">- Fonnesbæk Kirke</a>
</div>
</div>
Jeg har fundet frem til at det er menu(1); som får menuen til at folde sig ud, og derfor tænkte jeg at hvis jeg tilføjede en onLoad="menu(2);" i bodyens onload, så ville den selv folde den rigtig menu ud, men desværre virker det ikke.
Er der nogen, der kan hjælpe mig med at få det til at virke?
Mvh. Emilbp
[Redigeret d. 19/10-05 10:32:52 af Emil Bjerglund Pedersen]