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 Coder
    Join Date
    Jul 2002
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    finding an image's top position?

    How can I figure out where the top of an image is on a page? I've tried imageTop = document.getElementById('add').style.top; but it's not giving me anything. It's alerting, but just an empty value. So, I'm not sure what I'm doing wrong. Thanks.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    If you do not have the image defined, then that is not going to work

    You would have to use a code like this:

    Code:
      ErrorGapX=0;
      ErrorGapY=0;
      
      function ErrorPosition(ErrorElement){ 
        ErrorPosX = ErrorElement.offsetLeft
        ErrorPosY = ErrorElement.offsetTop;
        ErrorWidth = ErrorElement.clientWidth;
        TheElement = ErrorElement.offsetParent;
        while(TheElement != null){
           ErrorPosX += TheElement.offsetLeft 
           ErrorPosY += TheElement.offsetTop;
           TheElement = TheElement.offsetParent;
        }
        ErrorPosX += ErrorGapX;
        ErrorPosY += ErrorGapY;
        return ErrorPosX + "|" + ErrorPosY;
      }
    
    
     //Use this to find the position by setting variable TheObj
          Spot=ErrorPosition(TheObj);
          Spot=Spot.split("|");
          Cx=Spot[0]*1;
          Cy=Spot[1]*1;

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

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