Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing a appending a variable name through function parameters.

    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!
    Take your business to the next level.
    http://designlevel2.com

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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
    Last edited by Mr J; 05-11-2003 at 08:06 PM.

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it. Thanks guys
    Take your business to the next level.
    http://designlevel2.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •