Hi,
I need a FoldoutMenu such as Thomas Brattli's at
http://www.dhtmlcentral.com/script/?m=14, but with a modification. I hope
you can help me:
I have a site like this
.....text.....
[PIC] choice 0
.....text.....
[PIC] choice 1
.....text.....
[PIC] choice 2
.....text.....
At first you must know, that I have no idea of javascript, I'm programming
in PHP.
Now I have two problems:
1.) I can't position the foldoutmenus like simple text. I have changed
"position:absol ute;" to "position:relat ive" and then I have put every line
in a table. It worked some way, but in my sample-code in attachement you
see, that choice 2 is below blablabla7 and not below blablabla6 as I coded
it.
2.) Every choice reserves the space of his sub. Is there any way, that it
moves the whole text below text below, as it is clicked?
Thanks a lot!
John
------------------------------------------------------------
<html>
<head>
<title>DHTMLCen tral.com - Free Dynamic HTML Scripts - FoldoutMenu
Demo</title>
<meta name="Author" content="Thomas Brattli (webmaster@dhtm lcentral.com)">
<META NAME="Generator " CONTENT="Design er:Thomas Brattli (www.bratta.com )">
<meta name="KeyWords" content="DHTML, HTML, Dynamic HTML, Javascript,
Cascading Style Sheets, Cross-browser, Cross browser, Javascripts, DOM,
Scripts, Free
Scripts,menu,fo ldoutmenu,hiera rchical,expanda ble,collapsable ,outlines,">
<meta name="Descripti on" content="Dynami c HTML Central - The ultimate place
to find DHTML scripts, demos, tutorials and help.">
<style type="text/css">
#divCont {position:relat ive; visibility:hidd en;}
.clTop {position:relat ive;}
.clSub {position:relat ive;}
/*** This sets the style for the links inside the menu. ***/
#divCont .clTop a {color:#000000;
font-family:verdana, arial,helvetica ,sans-serif; font-size:14px;
font-weight:bold; text-decoration:none ;}
#divCont .clTop a:hover {color:#000000; text-decoration:none ;}
#divCont .clTop .clSub a {color:#777777;
font-family:verdana, arial,helvetica ,sans-serif; font-size:12px;
font-weight:normal; text-decoration:none ;}
#divCont .clTop .clSub a:hover {color:#333333; text-decoration:none ;}
</style>
<script language="JavaS cript" type="text/javascript">
/*************** *************** *************** *************** ***************
*******
FoldoutMenu
* Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli. asp">Thomas
Brattli</a>
* This script was released at DHTMLCentral.co m
* Visit for more great scripts!
* This may be used and changed freely as long as this msg is intact!
* We will also appreciate any links you could give us.
*
* Made by <a href="/dhtmlcentral/thomas_brattli. asp">Thomas Brattli</a>
*************** *************** *************** *************** *************** *
*****/
function lib_bwcheck(){ //Browsercheck (needed)
this.ver=naviga tor.appVersion
this.agent=navi gator.userAgent
this.dom=docume nt.getElementBy Id?1:0
this.opera5=thi s.agent.indexOf ("Opera 5")>-1
this.ie5=(this. ver.indexOf("MS IE 5")>-1 && this.dom && !this.opera5)?1 :0;
this.ie6=(this. ver.indexOf("MS IE 6")>-1 && this.dom && !this.opera5)?1 :0;
this.ie4=(docum ent.all && !this.dom && !this.opera5)?1 :0;
this.ie=this.ie 4||this.ie5||th is.ie6
this.mac=this.a gent.indexOf("M ac")>-1
this.ns6=(this. dom && parseInt(this.v er) >= 5) ?1:0;
this.ns4=(docum ent.layers && !this.dom)?1:0;
this.bw=(this.i e6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 ||
this.opera5)
return this
}
var bw=new lib_bwcheck()
/*** variables you can configure ***/
FoldNumber = 3 //How many toplinks do you have?
var stayFolded = false //Stay open when you click a new toplink?
foldImg = 0 //Do you want images (if not set to 0 and remove the images
from the body)?
mainOffsetY = 0 //Vertical space adjustment between the main items, in
pixels.
//This is the default image.
//Remember to change the actual images in the page as well, but remember to
keep the name of the image.
var unImg=new Image();
unImg.src='fold outmenu_arrow.g if'
var exImg=new Image(); //Making an image variable...
exImg.src='fold outmenu_arrow_o pen.gif' //...this is the source of the image
that it changes to when the menu expands.
// NOTE: if you change the position of divCont from absolute to relative,
you can put the foldoutmenu in a table.
// HOWEVER it will no longer work in netscape 4. If you wish to support
netscape 4, you have to use absolute positioning.
/*** There should be no need to change anything beyond this. ***/
// A unit of measure that will be added when setting the position of a
layer.
var px = bw.ns4||window. opera?"":"px";
if(navigator.us erAgent.indexOf ('Opera')>-1 && document.getEle mentById){
//Opera 5 resize fix.
scrX= innerWidth; scrY= innerHeight;
document.onmous emove= function(){
if(scrX<innerWi dth-10 || scrY<innerHeigh t-10 || scrX>innerWidth +10 ||
scrY>innerHeigh t+10){
scrX = innerWidth;
scrY = innerHeight;
initFoldout();
}
};
}
//object constructor...
function makeMenu(obj,ne st){
nest= (!nest)?"":'doc ument.'+nest+'. ';
this.el=
bw.ie4?document .all[obj]:bw.ns4?eval(ne st+'document.'+ obj):document.g etEleme
ntById(obj);
this.css= bw.ns4?this.el: this.el.style;
this.ref= bw.ns4?this.el. document:docume nt;
this.x= (bw.ns4||bw.ope ra5)?this.css.l eft:this.el.off setLeft;
this.y= (bw.ns4||bw.ope ra5)?this.css.t op:this.el.offs etTop;
this.h=
(bw.ie||bw.ns6) ?this.el.offset Height:bw.ns4?t his.ref.height: bw.opera5?this. c
ss.pixelHeight: 0;
this.vis= b_vis;
this.hideIt= b_hideIt;
this.showIt= b_showIt;
this.moveIt= b_moveIt;
return this
}
//object methods...
function b_showIt(){this .css.visibility ='visible'}
function b_hideIt(){this .css.visibility ='hidden'}
function b_vis(){if(this .css.visibility =='hidden' ||
this.css.visibi lity=='HIDDEN' || this.css.visibi lity=='hide') return true;}
function b_moveIt(x,y){t his.x=x; this.y=y; this.css.left=t his.x+px;
this.css.top=th is.y+px}
/*************** *************** *************** *************** ***************
*********
This is the function that changes the sub menus to folded or unfolded state.
*************** *************** *************** *************** *************** *
********/
function menu(num){
if(bw.bw){
if (!stayFolded){
for (var i=0; i<oSub.length; i++){
if (i!=num){
oSub[i].hideIt()
if (foldImg)oTop[i].ref["imgA"+i].src = unImg.src
}
}
for(var i=1; i<oTop.length; i++){
oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h)
}
}
if (oSub[num].vis()){
oSub[num].showIt()
if (foldImg)oTop[num].ref["imgA"+num].src = exImg.src
}else{
oSub[num].hideIt()
if(foldImg)oTop[num].ref["imgA"+num].src = unImg.src
}
for(var i=1; i<oTop.length; i++){
if (!oSub[i-1].vis())
oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+oSub[i-1].h+mainOffsetY)
else oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+mainOffsetY)
}
}
}
/*************** *************** *************** *************** *********
The init function... there should be no need to change anything here.
*************** *************** *************** *************** *********/
function initFoldout(){
//Fixing the browsercheck for opera... this can be removed if the
browsercheck has been updated!!
bw.opera5 = (navigator.user Agent.indexOf(" Opera")>-1 &&
document.getEle mentById)?true: false
if (bw.opera5) bw.ns6 = 0
oTop = new Array()
oSub = new Array()
//Making the objects and hiding the subs...
for (var i=0; i<FoldNumber; i++){
oTop[i] = new makeMenu('divTo p'+i,'divCont')
oSub[i] = new makeMenu('divSu b'+i,'divCont.d ocument.divTop' +i)
oSub[i].hideIt()
}
//Positioning the top objects...
oTop[0].moveIt(0,0)
for (var i=1; i<oTop.length; i++){
oTop[i].moveIt(0, oTop[i-1].y+oTop[i-1].h+mainOffsetY)
}
//Making the containing menu object and showing it...
oCont = new makeMenu('divCo nt')
oCont.showIt()
}
// If the browser is ok, the script is started onload...
if(bw.bw) onload = initFoldout;
</script>
</head>
<body marginleft="0" marginheight="0 ">
<div id="divCont"> <!-- These are the contents of the foldoutmenu. -->
<table>
<TR>
<TD>
TESTTITLE
</TD>
</TR>
<TR>
<TD>
<div id="divTop0" class="clTop">< a href="#" onclick="menu(0 ); return false"
onfocus="this.b lur()"><img src="foldoutmen u_arrow.gif" name="imgA0" width=12
height=12 alt="" border="0"> [choice 0]</a><br>
<div id="divSub0" class="clSub">
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
</div><br>
</div>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la<br><br>
</TD>
</TR>
<TR>
<TD>
<div id="divTop1" class="clTop">< a href="#" onclick="menu(1 ); return false"
onfocus="this.b lur()"><img src="foldoutmen u_arrow.gif" name="imgA1" width=12
height=12 alt="" border="0"> [choice 1]</a><br>
<div id="divSub1" class="clSub">
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
</div><br>
</div>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la2<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la3<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la4<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la5<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la6<br><br>
</TD>
</TR>
<TR>
<TD>
<div id="divTop2" class="clTop">< a href="#" onclick="menu(2 ); return false"
onfocus="this.b lur()"><img src="foldoutmen u_arrow.gif" name="imgA2" width=12
height=12 alt="" border="0"> [choice 2]</a><br>
<div id="divSub2" class="clSub">
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
</div><br>
</div>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la7<br><br>
</TD>
</TR>
</table>
</div> <!-- Here ends the foldoutmenu. -->
</body>
</html>
I need a FoldoutMenu such as Thomas Brattli's at
http://www.dhtmlcentral.com/script/?m=14, but with a modification. I hope
you can help me:
I have a site like this
.....text.....
[PIC] choice 0
.....text.....
[PIC] choice 1
.....text.....
[PIC] choice 2
.....text.....
At first you must know, that I have no idea of javascript, I'm programming
in PHP.
Now I have two problems:
1.) I can't position the foldoutmenus like simple text. I have changed
"position:absol ute;" to "position:relat ive" and then I have put every line
in a table. It worked some way, but in my sample-code in attachement you
see, that choice 2 is below blablabla7 and not below blablabla6 as I coded
it.
2.) Every choice reserves the space of his sub. Is there any way, that it
moves the whole text below text below, as it is clicked?
Thanks a lot!
John
------------------------------------------------------------
<html>
<head>
<title>DHTMLCen tral.com - Free Dynamic HTML Scripts - FoldoutMenu
Demo</title>
<meta name="Author" content="Thomas Brattli (webmaster@dhtm lcentral.com)">
<META NAME="Generator " CONTENT="Design er:Thomas Brattli (www.bratta.com )">
<meta name="KeyWords" content="DHTML, HTML, Dynamic HTML, Javascript,
Cascading Style Sheets, Cross-browser, Cross browser, Javascripts, DOM,
Scripts, Free
Scripts,menu,fo ldoutmenu,hiera rchical,expanda ble,collapsable ,outlines,">
<meta name="Descripti on" content="Dynami c HTML Central - The ultimate place
to find DHTML scripts, demos, tutorials and help.">
<style type="text/css">
#divCont {position:relat ive; visibility:hidd en;}
.clTop {position:relat ive;}
.clSub {position:relat ive;}
/*** This sets the style for the links inside the menu. ***/
#divCont .clTop a {color:#000000;
font-family:verdana, arial,helvetica ,sans-serif; font-size:14px;
font-weight:bold; text-decoration:none ;}
#divCont .clTop a:hover {color:#000000; text-decoration:none ;}
#divCont .clTop .clSub a {color:#777777;
font-family:verdana, arial,helvetica ,sans-serif; font-size:12px;
font-weight:normal; text-decoration:none ;}
#divCont .clTop .clSub a:hover {color:#333333; text-decoration:none ;}
</style>
<script language="JavaS cript" type="text/javascript">
/*************** *************** *************** *************** ***************
*******
FoldoutMenu
* Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli. asp">Thomas
Brattli</a>
* This script was released at DHTMLCentral.co m
* Visit for more great scripts!
* This may be used and changed freely as long as this msg is intact!
* We will also appreciate any links you could give us.
*
* Made by <a href="/dhtmlcentral/thomas_brattli. asp">Thomas Brattli</a>
*************** *************** *************** *************** *************** *
*****/
function lib_bwcheck(){ //Browsercheck (needed)
this.ver=naviga tor.appVersion
this.agent=navi gator.userAgent
this.dom=docume nt.getElementBy Id?1:0
this.opera5=thi s.agent.indexOf ("Opera 5")>-1
this.ie5=(this. ver.indexOf("MS IE 5")>-1 && this.dom && !this.opera5)?1 :0;
this.ie6=(this. ver.indexOf("MS IE 6")>-1 && this.dom && !this.opera5)?1 :0;
this.ie4=(docum ent.all && !this.dom && !this.opera5)?1 :0;
this.ie=this.ie 4||this.ie5||th is.ie6
this.mac=this.a gent.indexOf("M ac")>-1
this.ns6=(this. dom && parseInt(this.v er) >= 5) ?1:0;
this.ns4=(docum ent.layers && !this.dom)?1:0;
this.bw=(this.i e6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 ||
this.opera5)
return this
}
var bw=new lib_bwcheck()
/*** variables you can configure ***/
FoldNumber = 3 //How many toplinks do you have?
var stayFolded = false //Stay open when you click a new toplink?
foldImg = 0 //Do you want images (if not set to 0 and remove the images
from the body)?
mainOffsetY = 0 //Vertical space adjustment between the main items, in
pixels.
//This is the default image.
//Remember to change the actual images in the page as well, but remember to
keep the name of the image.
var unImg=new Image();
unImg.src='fold outmenu_arrow.g if'
var exImg=new Image(); //Making an image variable...
exImg.src='fold outmenu_arrow_o pen.gif' //...this is the source of the image
that it changes to when the menu expands.
// NOTE: if you change the position of divCont from absolute to relative,
you can put the foldoutmenu in a table.
// HOWEVER it will no longer work in netscape 4. If you wish to support
netscape 4, you have to use absolute positioning.
/*** There should be no need to change anything beyond this. ***/
// A unit of measure that will be added when setting the position of a
layer.
var px = bw.ns4||window. opera?"":"px";
if(navigator.us erAgent.indexOf ('Opera')>-1 && document.getEle mentById){
//Opera 5 resize fix.
scrX= innerWidth; scrY= innerHeight;
document.onmous emove= function(){
if(scrX<innerWi dth-10 || scrY<innerHeigh t-10 || scrX>innerWidth +10 ||
scrY>innerHeigh t+10){
scrX = innerWidth;
scrY = innerHeight;
initFoldout();
}
};
}
//object constructor...
function makeMenu(obj,ne st){
nest= (!nest)?"":'doc ument.'+nest+'. ';
this.el=
bw.ie4?document .all[obj]:bw.ns4?eval(ne st+'document.'+ obj):document.g etEleme
ntById(obj);
this.css= bw.ns4?this.el: this.el.style;
this.ref= bw.ns4?this.el. document:docume nt;
this.x= (bw.ns4||bw.ope ra5)?this.css.l eft:this.el.off setLeft;
this.y= (bw.ns4||bw.ope ra5)?this.css.t op:this.el.offs etTop;
this.h=
(bw.ie||bw.ns6) ?this.el.offset Height:bw.ns4?t his.ref.height: bw.opera5?this. c
ss.pixelHeight: 0;
this.vis= b_vis;
this.hideIt= b_hideIt;
this.showIt= b_showIt;
this.moveIt= b_moveIt;
return this
}
//object methods...
function b_showIt(){this .css.visibility ='visible'}
function b_hideIt(){this .css.visibility ='hidden'}
function b_vis(){if(this .css.visibility =='hidden' ||
this.css.visibi lity=='HIDDEN' || this.css.visibi lity=='hide') return true;}
function b_moveIt(x,y){t his.x=x; this.y=y; this.css.left=t his.x+px;
this.css.top=th is.y+px}
/*************** *************** *************** *************** ***************
*********
This is the function that changes the sub menus to folded or unfolded state.
*************** *************** *************** *************** *************** *
********/
function menu(num){
if(bw.bw){
if (!stayFolded){
for (var i=0; i<oSub.length; i++){
if (i!=num){
oSub[i].hideIt()
if (foldImg)oTop[i].ref["imgA"+i].src = unImg.src
}
}
for(var i=1; i<oTop.length; i++){
oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h)
}
}
if (oSub[num].vis()){
oSub[num].showIt()
if (foldImg)oTop[num].ref["imgA"+num].src = exImg.src
}else{
oSub[num].hideIt()
if(foldImg)oTop[num].ref["imgA"+num].src = unImg.src
}
for(var i=1; i<oTop.length; i++){
if (!oSub[i-1].vis())
oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+oSub[i-1].h+mainOffsetY)
else oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+mainOffsetY)
}
}
}
/*************** *************** *************** *************** *********
The init function... there should be no need to change anything here.
*************** *************** *************** *************** *********/
function initFoldout(){
//Fixing the browsercheck for opera... this can be removed if the
browsercheck has been updated!!
bw.opera5 = (navigator.user Agent.indexOf(" Opera")>-1 &&
document.getEle mentById)?true: false
if (bw.opera5) bw.ns6 = 0
oTop = new Array()
oSub = new Array()
//Making the objects and hiding the subs...
for (var i=0; i<FoldNumber; i++){
oTop[i] = new makeMenu('divTo p'+i,'divCont')
oSub[i] = new makeMenu('divSu b'+i,'divCont.d ocument.divTop' +i)
oSub[i].hideIt()
}
//Positioning the top objects...
oTop[0].moveIt(0,0)
for (var i=1; i<oTop.length; i++){
oTop[i].moveIt(0, oTop[i-1].y+oTop[i-1].h+mainOffsetY)
}
//Making the containing menu object and showing it...
oCont = new makeMenu('divCo nt')
oCont.showIt()
}
// If the browser is ok, the script is started onload...
if(bw.bw) onload = initFoldout;
</script>
</head>
<body marginleft="0" marginheight="0 ">
<div id="divCont"> <!-- These are the contents of the foldoutmenu. -->
<table>
<TR>
<TD>
TESTTITLE
</TD>
</TR>
<TR>
<TD>
<div id="divTop0" class="clTop">< a href="#" onclick="menu(0 ); return false"
onfocus="this.b lur()"><img src="foldoutmen u_arrow.gif" name="imgA0" width=12
height=12 alt="" border="0"> [choice 0]</a><br>
<div id="divSub0" class="clSub">
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
</div><br>
</div>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la<br><br>
</TD>
</TR>
<TR>
<TD>
<div id="divTop1" class="clTop">< a href="#" onclick="menu(1 ); return false"
onfocus="this.b lur()"><img src="foldoutmen u_arrow.gif" name="imgA1" width=12
height=12 alt="" border="0"> [choice 1]</a><br>
<div id="divSub1" class="clSub">
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
</div><br>
</div>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la2<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la3<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la4<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la5<br><br>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la6<br><br>
</TD>
</TR>
<TR>
<TD>
<div id="divTop2" class="clTop">< a href="#" onclick="menu(2 ); return false"
onfocus="this.b lur()"><img src="foldoutmen u_arrow.gif" name="imgA2" width=12
height=12 alt="" border="0"> [choice 2]</a><br>
<div id="divSub2" class="clSub">
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
<a href="#">This is a link</a><br>
</div><br>
</div>
</TD>
</TR>
<TR>
<TD>
<br><br>blablab la7<br><br>
</TD>
</TR>
</table>
</div> <!-- Here ends the foldoutmenu. -->
</body>
</html>
Comment