div - position - offsetParent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vittore Zen

    div - position - offsetParent

    Hi,

    a little question.

    I have some nested tables with some divs (so default set is relative - ok?)

    Now, i need to draw a line from one div to another. The problem is to
    find the position of div

    I use these functions:

    function findPosX(obj)
    {
    var curleft = 0;
    if (obj.offsetPare nt)
    {
    while (obj.offsetPare nt)
    {
    curleft += obj.offsetLeft
    obj = obj.offsetParen t;
    }
    }
    else if (obj.x)
    curleft += obj.x;
    return curleft;
    }

    function findPosY(obj)
    {
    var curtop = 0;
    if (obj.offsetPare nt)
    {
    while (obj.offsetPare nt)
    {
    curtop += obj.offsetTop
    obj = obj.offsetParen t;
    }
    }
    else if (obj.y)
    curtop += obj.y;
    return curtop;
    }



    But these give an error on offsetParent. The browser (IE 6) says that is
    null (or it isn't a object).

    Any idea?

    Thanks
    v.
  • Martin Honnen

    #2
    Re: div - position - offsetParent



    Vittore Zen wrote:
    [color=blue]
    > I have some nested tables with some divs (so default set is relative - ok?)[/color]

    What is "default set"?
    [color=blue]
    > Now, i need to draw a line from one div to another. The problem is to
    > find the position of div
    >
    > I use these functions:
    >
    > function findPosX(obj)
    > {
    > var curleft = 0;
    > if (obj.offsetPare nt)
    > {
    > while (obj.offsetPare nt)
    > {
    > curleft += obj.offsetLeft
    > obj = obj.offsetParen t;
    > }
    > }[/color]

    I would rather use
    if (typeof obj.offsetLeft != 'undefined') {
    do {
    curleft += obj.offsetLeft;
    obj = obj.offsetParen t;
    }
    while (obj)
    }
    [color=blue]
    > But these give an error on offsetParent. The browser (IE 6) says that is
    > null (or it isn't a object).[/color]

    For which line? And what do you pass in as obj when you call the function?

    --

    Martin Honnen

    Comment

    Working...