Metachecker.net
|
FontsMadeEasy.com
|
RankChecker.net
Learn Java Script Today
|
Over 5000 Free Fonts
|
Tutorials
|
Javascript Forum
|
Other Javascript Resources
|
Cheat Sheet
JavaScript Basics
Inserting Javascript
Complete Tutorial
Advance DHTML Tutorial
Script archive
Advanced Tutorials
Alert Scripts
Animation
Audio
Background Effects
Banner Ads
Browser Window
Buttons
Button Forms
Calculcators
Calendars
Clocks & Dates
Cookies
Cursor Effects
DHMTL Games
DHTML Miscellaneous
Equivalents
Forms
Games
IE4+ Scripts
IE5+ Scripts
Image Effects
Image Miscellaneous
Links & Buttons
Math Related
Messages Miscellaneous
Miscellaneous
Mouse Tricks
Navigation
Page Details
Password Protection
Pulldown Menus
Random Stuff
Scrolling
Status Bar
Text Animation
User Detail
User Info
Window Control
DHTML Script - Foldoutmenu2
[View Sample]
The same as the foldoutmenu only this one includes another level of menus. This one also works in several different ways. Play with these variables:
Insert into <HEAD>
<style type="text/css"> DIV.clFold{position:absolute; width:170; clip:rect(0,170,300,0)} DIV.clFoldSub{position:absolute; left:10; width:170; visibility:hidden} DIV.clFoldSub2{position:absolute; left:20; width:160; visibility:hidden} #divFoldCont{position:relative; left:80; top:-100; height:600; width:170; visibility:hidden} A.clFoldLinks{font-family:Arial, Verdana, Helvetica, Helv; font-size:15px; text-decoration:none; font-weight:bold; color:black} A.clSubLinks{font-family:Arial, Verdana, Helvetica, Helv; font-size:13px; font-weight:bold; text-decoration:none; color:black} A.clSubLinks2{font-family:Arial, Verdana, Helvetica, Helv; font-size:12px; text-decoration:none; color:black} </style> <script type="text/javascript" language="JavaScript"> /******************************************************************************** Copyright (C) 1999 Thomas Brattli This script is made by and copyrighted to Thomas Brattli at www.bratta.com Visit for more great scripts. This may be used freely as long as this msg is intact! I will also appriciate any links you could give me. ********************************************************************************/ //Default browsercheck, added to all scripts! function checkBrowser(){ this.ver=navigator.appVersion this.dom=document.getElementById?1:0 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; this.ie4=(document.all && !this.dom)?1:0; this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers && !this.dom)?1:0; this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) return this } bw=new checkBrowser() /************************************************************************************ This is the new foldoutmenu, with more levels! This is in some ways a rather advanced menu so please read every note in this script and in the comments in the page to understand how it works. ************************************************************************************/ //Do you want images (if not set to 0 and remove the images from the body)? foldImg=1 //Here are the images for the top links. foldinImg=new Image(); foldinImg.src="images/foldarrowin.gif" //The image for the "in" state. foldoutImg=new Image(); foldoutImg.src="images/foldarrowout.gif" //The image for the "out" state. //Here are the images for the sub links. foldsubinImg=new Image(); foldsubinImg.src="images/foldsubarrowin.gif" //The image for the "in" state. foldsuboutImg=new Image(); foldsuboutImg.src="images/foldsubarrowout.gif" //The image for the "out" state. //If you change the images above please remember to change the images in the actual page as well. mainmenus=4 //How many main menus do you have? //How many submenus do you have beneath each main level. submenus=new Array(3,3,2,3) //In this example I have 3 submenus in the first top menu, //3, in the second, 2 submenus in the third top menu and 3 in the forth. //It's really important that these numbers are correct. pxbetweenmain=10 //How much space should there be between the main menus pxbetweensub=5 //How much space should there be between the sub menus mainstayfolded=false //Should the main menus stay folded? substayfolded=false //Should the sub menus stay folded? Play with these 2 variables. /************************************************************************************ Making cross-browser objects ************************************************************************************/ function makeMenu(obj,nest){ nest=(!nest) ? '':'document.'+nest+'.' this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0; this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; this.ref=bw.dom || bw.ie4? document:bw.ns4?eval(nest+"document.layers." +obj+".document"):0; this.x=(bw.ns4 || bw.ns5)? this.css.left:this.css.pixelLeft; this.y=(bw.ns4 || bw.ns5)? this.css.top:this.css.pixelTop; this.height=bw.ns4?this.ref.height:this.el.offsetHeight; this.hideIt=b_hideIt; this.showIt=b_showIt; this.moveIt=b_moveIt this.status=0; return this } function b_showIt(){this.css.visibility="visible"; this.status=1} function b_hideIt(){this.css.visibility="hidden"; this.status=0} function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x; this.css.top=this.y} /************************************************************************************ Initiating the page and making the menu ************************************************************************************/ function foldInit(){ //Creating the foldoutmenu oFold=new Array(); y=0 for(i=0;i<mainmenus;i++){ oFold[i]=new makeMenu('divFold'+i,'divFoldCont') oFold[i].moveIt(0,y); oFold[i].size=oFold[i].height y+=oFold[i].height+pxbetweenmain oFold[i].sub=new Array() oFold[i].subs=top_subs; suby=oFold[i].height+pxbetweensub for(j=0;j<submenus[i];j++){ oFold[i].sub[j]=new makeMenu('divFoldSub'+i+'_'+j,'divFoldCont.document.divFold'+i) oFold[i].sub[j].sub=new makeMenu('divFoldSub'+i+'_'+j+'_0','divFoldCont.document.divFold'+i+'.document.divFoldSub'+i+'_'+j) oFold[i].sub[j].hideIt(); oFold[i].sub[j].sub.hideIt() oFold[i].sub[j].moveIt(10,suby) suby+=oFold[i].sub[j].height+pxbetweensub } } oFoldCont=new makeMenu('divFoldCont') oFoldCont.showIt() //Showing the menu when the menu have been "created" } /************************************************************************************ Object function to the top of the menus. ************************************************************************************/ function top_subs(show,num){ for(j=0;j<this.sub.length;j++){ if(show){ this.sub[j].showIt() if(foldImg) this.ref["imgFold"+num].src=foldoutImg.src if(substayfolded){if(this.sub[j].sub.status) this.sub[j].sub.showIt() }else{ if(foldImg) this.sub[j].ref["imgFold"+num+"Sub"+j].src=foldsubinImg.src this.sub[j].sub.hideIt() } }else{ this.sub[j].hideIt() if(foldImg) this.ref["imgFold"+num].src=foldinImg.src if(!substayfolded) this.sub[j].sub.hideIt() else if(substayfolded) this.sub[j].sub.css.visibility="hidden" } } } /************************************************************************************ Checking height of the menus, and moves them to the correct position. ************************************************************************************/ function checkheight(org){ if(mainstayfolded) istart=org; else istart=0 for(i=istart;i<oFold.length;i++){ oFold[i].size=oFold[i].height for(j=0;j<oFold[i].sub.length;j++){ oFold[i].sub[j].size=oFold[i].sub[j].height+pxbetweensub if(oFold[i].sub[j].status){ oFold[i].size+=oFold[i].sub[j].size if(oFold[i].sub[j].sub.status){ oFold[i].size+=oFold[i].sub[j].sub.height+pxbetweensub oFold[i].sub[j].size+=oFold[i].sub[j].sub.height+pxbetweensub } } if(j!=0) oFold[i].sub[j].moveIt(10,oFold[i].sub[j-1].y+oFold[i].sub[j-1].size) } if(i!=0) oFold[i].moveIt(0,oFold[i-1].y+oFold[i-1].size+pxbetweenmain) } } /************************************************************************************ Fold in and out the submenus. ************************************************************************************/ function subfoldmenu(main,sub){ if(!substayfolded){ for(i=0;i<oFold[main].sub.length;i++){if(i!=sub){ oFold[main].sub[i].sub.hideIt(); if(foldImg) oFold[main].sub[i].ref["imgFold"+main+"Sub"+i].src=foldsubinImg.src}} } if(!oFold[main].sub[sub].sub.status){ oFold[main].sub[sub].sub.showIt() if(foldImg) oFold[main].sub[sub].ref["imgFold"+main+"Sub"+sub].src=foldsuboutImg.src }else{ oFold[main].sub[sub].sub.hideIt() if(foldImg) oFold[main].sub[sub].ref["imgFold"+main+"Sub"+sub].src=foldsubinImg.src } checkheight(main) } /************************************************************************************ Fold in and out the mainmenus ************************************************************************************/ function foldmenu(num){ if(!mainstayfolded){for(i=0;i<oFold.length;i++){if(i!=num) oFold[i].subs(0,i)}} if(!oFold[num].sub[0].status)oFold[num].subs(1,num) else oFold[num].subs(0,num) checkheight(num) } //Initiating the menus onload, if it's a 4.x+ browser. if(bw.bw) onload=foldInit; </script>
Insert into <BODY>
<!-- Menu container --> <div id="divFoldCont"> <!-- Top 1 --> <div id="divFold0" class="clFold"><a href="#" onclick="foldmenu(0); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clFoldLinks"><img src="images/foldarrowin.gif" name="imgFold0" width=12 height=12 alt="" border=0> [choice 0]</a><br> <div id="divFoldSub0_0" class="clFoldSub"><a href="#" onclick="subfoldmenu(0,0); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold0Sub0" width=10 height=10 alt="" border=0> [choice 0_0]</a><br> <div id="divFoldSub0_0_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 0_0_0</a><br> <a href="#" class="clSubLinks2">-Sub 0_0_1</a><br> <a href="#" class="clSubLinks2">-Sub 0_0_2</a><br> </div> </div> <div id="divFoldSub0_1" class="clFoldSub"><a href="#" onclick="subfoldmenu(0,1); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold0Sub1" width=10 height=10 alt="" border=0> [choice 0_1]</a><br> <div id="divFoldSub0_1_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 0_1_0</a><br> <a href="#" class="clSubLinks2">-Sub 0_1_1</a><br> <a href="#" class="clSubLinks2">-Sub 0_1_2</a><br> <a href="#" class="clSubLinks2">-Sub 0_1_3</a><br> <a href="#" class="clSubLinks2">-Sub 0_1_4</a><br> <a href="#" class="clSubLinks2">-Sub 0_1_5</a><br> </div> </div> <div id="divFoldSub0_2" class="clFoldSub"><a href="#" onclick="subfoldmenu(0,2); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold0Sub2" width=10 height=10 alt="" border=0> [choice 0_2]</a><br> <div id="divFoldSub0_2_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 0_2_0</a><br> <a href="#" class="clSubLinks2">-Sub 0_2_1</a><br> <a href="#" class="clSubLinks2">-Sub 0_2_2</a><br> <a href="#" class="clSubLinks2">-Sub 0_2_3</a><br> </div> </div> <!-- Here's an example of how the next "submenu" will look: <div id="divFoldSub0_3" class="clFoldSub"><a href="#" onclick="subfoldmenu(0,3); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold0Sub3" width=10 height=10 alt="" border=0> [choice 0_3]</a><br> <div id="divFoldSub0_3_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 0_3_0</a><br> <a href="#" class="clSubLinks2">-Sub 0_3_1</a><br> <a href="#" class="clSubLinks2">-Sub 0_3_2</a><br> <a href="#" class="clSubLinks2">-Sub 0_3_3</a><br> </div> </div> Note all the numbers that are changed: divFoldSub0_CHANGED subfoldmenu(0,CHANGED) imgFold0SubCHANGED divFoldSub0_CHANGED_0 Locate those places to see where the numbers should be increased by one each time. If you add more submenus be sure to change it in the submenus array as well. --> </div> <!-- Top 2 --> <div id="divFold1" class="clFold"><a href="#" onclick="foldmenu(1); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clFoldLinks"><img src="images/foldarrowin.gif" name="imgFold1" width=12 height=12 alt="" border=0> [choice 1]</a><br> <div id="divFoldSub1_0" class="clFoldSub"><a href="#" onclick="subfoldmenu(1,0); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold1Sub0" width=10 height=10 alt="" border=0> [choice 1_0]</a><br> <div id="divFoldSub1_0_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 1_0_0</a><br> <a href="#" class="clSubLinks2">-Sub 1_0_1</a><br> </div> </div> <div id="divFoldSub1_1" class="clFoldSub"><a href="#" onclick="subfoldmenu(1,1); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold1Sub1" width=10 height=10 alt="" border=0> [choice 1_1]</a><br> <div id="divFoldSub1_1_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 1_1_0</a><br> <a href="#" class="clSubLinks2">-Sub 1_1_1</a><br> <a href="#" class="clSubLinks2">-Sub 1_1_2</a><br> <a href="#" class="clSubLinks2">-Sub 1_1_3</a><br> </div> </div> <div id="divFoldSub1_2" class="clFoldSub"><a href="#" onclick="subfoldmenu(1,2); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold1Sub2" width=10 height=10 alt="" border=0> [choice 1_2]</a><br> <div id="divFoldSub1_2_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 1_2_0</a><br> <a href="#" class="clSubLinks2">-Sub 1_2_1</a><br> <a href="#" class="clSubLinks2">-Sub 1_2_2</a><br> <a href="#" class="clSubLinks2">-Sub 1_2_3</a><br> </div> </div> </div> <!-- Top 3 --> <div id="divFold2" class="clFold"><a href="#" onclick="foldmenu(2); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clFoldLinks"><img src="images/foldarrowin.gif" name="imgFold2" width=12 height=12 alt="" border=0> [choice 2]</a><br> <div id="divFoldSub2_0" class="clFoldSub"><a href="#" onclick="subfoldmenu(2,0); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold2Sub0" width=10 height=10 alt="" border=0> [choice 2_0]</a><br> <div id="divFoldSub2_0_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 2_0_0</a><br> <a href="#" class="clSubLinks2">-Sub 2_0_1</a><br> <a href="#" class="clSubLinks2">-Sub 2_0_2</a><br> </div> </div> <div id="divFoldSub2_1" class="clFoldSub"><a href="#" onclick="subfoldmenu(2,1); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold2Sub1" width=10 height=10 alt="" border=0> [choice 2_1]</a><br> <div id="divFoldSub2_1_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 2_1_0</a><br> </div> </div> </div> <div id="divFold3" class="clFold"><a href="#" onclick="foldmenu(3); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clFoldLinks"><img src="images/foldarrowin.gif" name="imgFold3" width=12 height=12 alt="" border=0> [choice 3]</a><br> <div id="divFoldSub3_0" class="clFoldSub"><a href="javascript://this link doesn't have a onclick, and can be used just like a regular link" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold3Sub0" width=10 height=10 alt="" border=0> [empty]</a> <div id="divFoldSub3_0_0" class="clFoldSub2"></div> </div> <div id="divFoldSub3_1" class="clFoldSub"><a href="#" onclick="subfoldmenu(3,1); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold3Sub1" width=10 height=10 alt="" border=0> [choice 3_1]</a><br> <div id="divFoldSub3_1_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 3_1_0</a><br> <a href="#" class="clSubLinks2">-Sub 3_1_1</a><br> <a href="#" class="clSubLinks2">-Sub 3_1_2</a><br> </div> </div> <div id="divFoldSub3_2" class="clFoldSub"><a href="#" onclick="subfoldmenu(3,2); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold3Sub2" width=10 height=10 alt="" border=0> [choice 3_2]</a><br> <div id="divFoldSub3_2_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 3_2_0</a><br> <a href="#" class="clSubLinks2">-Sub 3_2_1</a><br> <a href="#" class="clSubLinks2">-Sub 3_2_2</a><br> <a href="#" class="clSubLinks2">-Sub 3_2_3</a><br> </div> </div> </div> <!-- Here's how it would look if we added one more top menu. (in this case a top menu with one sublevel. <div id="divFold4" class="clFold"><a href="#" onclick="foldmenu(4); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clFoldLinks"><img src="images/foldarrowin.gif" name="imgFold4" width=12 height=12 alt="" border=0> [choice 4]</a><br> <div id="divFoldSub4_0" class="clFoldSub"><a href="#" onclick="subfoldmenu(4,0); if(bw.ie5 || bw.ie4) this.blur(); return false" class="clSubLinks"><img src="images/foldsubarrowin.gif" name="imgFold4Sub0" width=10 height=10 alt="" border=0> [choice 4_0]</a><br> <div id="divFoldSub4_0_0" class="clFoldSub2"> <a href="#" class="clSubLinks2">-Sub 4_0_0</a><br> </div> </div> </div> Note all the places the numbers changed: divFoldCHANGED foldmenu(CHANGED) imgFoldCHANGED divFoldSubCHANGED_0 subfoldmenu(CHANGED,0) imgFoldCHANGEDSub0 divFoldSubCHANGED_0_0 Locate those places to see where the numbers should be increased by one each time. If you add more topmenus be sure to change the "mainmenus" variable and add it in the "submenus" array. --> </div>
Other Options