hybridsun
04-04-2003, 01:44 AM
I have a function that works beatifully. However it has hard coded
values in it defining the layer.style in it. Since Im using this
function 5 or 6 times on the page I want to consolidate the function
into one function. Heres the thing. I have labeled my layers: menu0,
menu1, menu2, etc.) So I think it should be possible to change the
variable called in my function (block0, block1, block2) using the
paramter.
Any insight would be nice.
Here's some sample code:
function init() {
if (ns4) block0 = document.menu0
if (ie4) block0 = menu0.style
block0.ypos = parseInt(block0.top)
if (ns4) block1 = document.menu1
if (ie4) block1 = menu1.style
block1.ypos = parseInt(block1.top)
if (ns4) block2 = document.menu2
if (ie4) block2 = menu2.style
//........................ETC, ETC
}
function slidemenu0up() {
if (ie4){
// alert ('IE, damn you for supporting microsoft but its the only
choice')
if (block0.ypos > 15) {
block0.ypos -= 8
block0.top = block0.ypos
setTimeout("slidemenu0up()",30)
}
}
else {
// alert ('navigator sucks')
moveLayerTo('menu0',333,15)
}
}
So to recap I want to pass the parameter 1,2,3 etc like slidemenuup(1)
but Im having some problems.
I tried this: but it didnt work
function slidemenuup(menuNo) {
if (ie4){
if (("block"+menuNo+".ypos") > 15) {
eval("block"+menuNo+".ypos") -= 8
("block"+menuNo).top = ("block"+menuNo).ypos
setTimeout("slidemenuup(menuNo)",30)
}
}
else {
moveLayerTo('menu2',333,15)
}
}
Thanks in advance!
values in it defining the layer.style in it. Since Im using this
function 5 or 6 times on the page I want to consolidate the function
into one function. Heres the thing. I have labeled my layers: menu0,
menu1, menu2, etc.) So I think it should be possible to change the
variable called in my function (block0, block1, block2) using the
paramter.
Any insight would be nice.
Here's some sample code:
function init() {
if (ns4) block0 = document.menu0
if (ie4) block0 = menu0.style
block0.ypos = parseInt(block0.top)
if (ns4) block1 = document.menu1
if (ie4) block1 = menu1.style
block1.ypos = parseInt(block1.top)
if (ns4) block2 = document.menu2
if (ie4) block2 = menu2.style
//........................ETC, ETC
}
function slidemenu0up() {
if (ie4){
// alert ('IE, damn you for supporting microsoft but its the only
choice')
if (block0.ypos > 15) {
block0.ypos -= 8
block0.top = block0.ypos
setTimeout("slidemenu0up()",30)
}
}
else {
// alert ('navigator sucks')
moveLayerTo('menu0',333,15)
}
}
So to recap I want to pass the parameter 1,2,3 etc like slidemenuup(1)
but Im having some problems.
I tried this: but it didnt work
function slidemenuup(menuNo) {
if (ie4){
if (("block"+menuNo+".ypos") > 15) {
eval("block"+menuNo+".ypos") -= 8
("block"+menuNo).top = ("block"+menuNo).ypos
setTimeout("slidemenuup(menuNo)",30)
}
}
else {
moveLayerTo('menu2',333,15)
}
}
Thanks in advance!