...

View Full Version : Passing a appending a variable name through function parameters.



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!

Mr J
04-04-2003, 10:47 PM
Have a play with the following




<script language="javascript">
<!--
Position=100
function moveme(n){

Position+=50
document.getElementById(n).style.pixelLeft=Position
N=n
rerun=setTimeout("moveme(N)",100)

page_width=document.body.clientWidth
layer_width=parseInt(document.getElementById(n).style.width)

if(Position>=page_width-layer_width){
clearTimeout(rerun)
document.getElementById(n).style.pixelLeft=100
Position=100
}
}
// -->
</script>
<div id="DIV1" style="position:absolute; left:100; top:50; width:100; height:50; background-color:green"></div>
<div id="DIV2" style="position:absolute; left:100; top:150; width:100; height:50; background-color:yellow"></div>
<div id="DIV3" style="position:absolute; left:100; top:250; width:100; height:50; background-color:red"></div>
<div id="DIV4" style="position:absolute; left:100; top:350; width:100; height:50; background-color:blue"></div>
<a href="#null" onclick="moveme('DIV1')">Move One</a><BR>
<a href="#null" onclick="moveme('DIV2')">Move Two</a><BR>
<a href="#null" onclick="moveme('DIV3')">Move Three</a><BR>
<a href="#null" onclick="moveme('DIV4')">Move Four</a><BR>



The divs should be one line

hybridsun
05-11-2003, 07:55 PM
I got it. Thanks guys



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum