SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast sangharsha's Avatar
    Join Date
    Mar 2005
    Location
    Kathmandu, Oklahoma, New Delhi
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting the scrolled offset of a DIV

    I need to know how much a overflowing div has been scrolled.

    For instance,
    Code JavaScript:
    document.body.scrollTop
    gives the over all scrolled size of the window. But I only need to know the scrolled offset of the current div.

    Example code:
    Code HTML4Strict:
    <div style="width:350px;height:350px;overflow:auto;padding:0px;margin:0px; border:#999999 1px solid;" id="divLeftTree">
    <br /><br /><br /><br /><br /><br /><br />
    info here
    <br /><br /><br /><br /><br /><br /><br /><br />
    </div>

    Here, I need to know how much the floating DIV has been scrolled.

    Does anyone have any idea on this?
    Thanks in advance.

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the scrollTop property of that div element (instead of document.body)?

  3. #3
    SitePoint Enthusiast sangharsha's Avatar
    Join Date
    Mar 2005
    Location
    Kathmandu, Oklahoma, New Delhi
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I tried that too, but it didnt work

    Code JavaScript:
    eltDiv = document.getElementById('divLeftTree');
    tmpScrollY    =    document.eltDiv.scrollTop;
    alert("ScrollY of Div: " + tmpScrollY);
    I used this snippet to access the scrollTop of the div element, but this method is not supported by the object, neither in IE nor in FF.

    Can you try this?
    Thanks

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    If more details about the overall plan is provided, some bright spark around here should be able to come up with a solution for you.

  5. #5
    SitePoint Enthusiast sangharsha's Avatar
    Join Date
    Mar 2005
    Location
    Kathmandu, Oklahoma, New Delhi
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Here goes my scenario

    Quote Originally Posted by pmw57 View Post
    If more details about the overall plan is provided, some bright spark around here should be able to come up with a solution for you.
    Thanks pmw57,
    My main motto is:
    - to find out how much the div is scrolled down.

    My overall scenario/plan is:
    - There is a main page with two panels, left panel and the right panel.
    - The left one holds a javascript tree which is enclosed within the above DIV, and it gets scrolled with the tree gets long.
    - The right panel holds normal body contents which gets elongated as the content grows.
    - Now, since the tree also grows in height, there appears a vertical scrollbar, which is desired and works fine. But the tree allows the node to be dragged and dropped, and thus i need to track the exact position of the mouse to display the drop indicator. Now here comes the flaw, this drop indicator doesnt get displayed in proper location depending upon the scrolled height of the div.
    Finally, if I could track the scrolled height, I could add the offset of the drop indicator by the scrolled height and the deviance would be neutralized.
    And here I needed to find the scrolled height of this particular DIV block.

    Is this clear enough?

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    So to clarify, you want to use javascript to drag and drop items in a vertically scrolled panel, with a drop indicator.

    Why don't you embed the scrolling indicator in the dom of the content, then use relative positioning to place the indicator where you want it.

  7. #7
    SitePoint Enthusiast sangharsha's Avatar
    Join Date
    Mar 2005
    Location
    Kathmandu, Oklahoma, New Delhi
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The same is done, but it is not browser compatible, and the indicator gets dislocated when the div section is scrolled

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    You're going to have to let us see just what's happening there.


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
  •