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
    "Q"
    "Q" is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using DOM to locate a menu on the screen. Code not working

    I have spent over 2 hours trying many variables to get a simple picture to move to the correct x and y position on the screen. To view the code please go to www.lybroworld.com.

    You will notice a red bar with links "menu 1" and "menu 2". When you click on them the desired affect is to have the pics line up under the correct heading but instead the top position is not working but the left is ok. What I don't under stand is that if you click on the other 2 random links the images line up.

    This leads me to belive that I am not accessing the DOM correctly in the menu bar as it works on the other two links properly.

    I am still a newbie with JavaScript so don't flame me for my lame code. I am trying to keep it simple until I quite making dumb mistakes so that I can debug it easier.

    Thanks,

    Matt

  • #2
    "Q"
    "Q" is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    WOOOOHOOOO I figured it out.

    I had this code

    function setTop(anchor) { var dom = document.getElementById(anchor);

    return dom.offsetHeight + dom.offsetTop + 5}

    The problem was with how JavaScript convets the strings and how CSS used the output. I added "5px" and the problem was resolved.

    I have to go back and do more reading on this to fully grasp it but that was the basic fix for this problem. The code on my example is not perfect yet there are still some bugs in it regarding the other links on the screen and element positioning but I can finally see the light

    Later,

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is accurate, any position you set should have the unit appended to it. Remember, style rules are strings, even if they look like numbers
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

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