SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    united states
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    bug in calculating the position of an element

    Hello

    I wrote a function which will find the exact top left coordinates in the screen.
    The function will return an associative array with information on the element:
    Code:
    function getPositionAndDimension(element) {
      var left = 0;
      var top = 0;
      var width = element.offsetWidth;
      var height = element.offsetHeight;
      while (element.parentElement != null) {
        left += element.offsetLeft;
        top += element.offsetTop;
        element = element.parentElement;
      }
    	
      var results = new Array(4);
      results['left'] = left;
      results['top'] = top;
      results['width'] = width;
      results['height'] = height;
    		
      return results;
    }
    The problem is that the value that the function calculates for the element's top is incorrect.
    I am getting values that are much larger than the actual top value.

    can anyone see where the bug is in?
    I am testing this on IE6

    thanks

  2. #2
    SitePoint Zealot Valera Selev's Avatar
    Join Date
    Apr 2004
    Location
    Lviv, Ukraine
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at klayers library - a nice bundle of useful cross-browser DHTML functions.


Bookmarks

Posting Permissions

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