How to force a scroll of div with overflow set to auto?

Discussion in 'Javascript' started by Martin, Feb 18, 2010.

  1. Martin

    Martin Guest

    I don't know if this is a javascript question or just html related.

    I'm displaying a table of data in a div with overflow set to "auto"
    (with a vertical scrollbar being used). Is there any way I can make it
    scroll down a certain distance?

    Here's the situation: the user gets the page and he manually scrolls
    down into the list. He finds what he's looking for and then clicks on
    a row in the table which requests a refresh of the page with some
    additional data being shown (elsewhere on the page). When this
    refreshed page comes in, I'd like to automatically scroll him down to
    where he was when he clicked.

    Possible?
    Martin, Feb 18, 2010
    #1
    1. Advertising

  2. Martin

    Scott Sauyet Guest

    On Feb 18, 11:47 am, Martin <> wrote:
    > Here's the situation: the user gets the page and he manually scrolls
    > down into the list. He finds what he's looking for and then clicks on
    > a row in the table which requests a refresh of the page with some
    > additional data being shown (elsewhere on the page). When this
    > refreshed page comes in, I'd like to automatically scroll him down to
    > where he was when he clicked.


    Have you tried scrollIntoView()? [1] It's not part of a spec, but I
    believe it's widely supported. I don't know if it will scroll your
    table as well as the page, but it's worth trying.

    Good luck,

    -- Scott
    ____________________
    [1] https://developer.mozilla.org/En/DOM/Element.scrollIntoView
    http://msdn.microsoft.com/en-us/library/ms536730(VS.85).aspx
    Scott Sauyet, Feb 18, 2010
    #2
    1. Advertising

  3. On Feb 18, 4:47 pm, Martin wrote:
    > I don't know if this is a javascript question or just
    > html related.


    If you cannot decide that for yourself what makes you think you are
    qualified to be designing/building a system like this?

    > I'm displaying a table of data in a div with overflow set
    > to "auto" (with a vertical scrollbar being used). Is there
    > any way I can make it scroll down a certain distance?


    Scripts can alter the distance by which an overflow auto DIV is
    scrolled by assigning to the Element's - scrollTop - property
    (negative values to scroll down) (or - scrollLeft - if left/right
    scrolling is wanted).

    > Here's the situation: the user gets the page and he manually
    > scrolls down into the list. He finds what he's looking for
    > and then clicks on a row in the table which requests a refresh
    > of the page with some additional data being shown (elsewhere
    > on the page). When this refreshed page comes in, I'd like to
    > automatically scroll him down to where he was when he clicked.


    In which case scrolling some certain distance requires that you find
    out that distance in some way (probably reading the current value from
    the element's - scrollTop - value prior to submitting).

    It is possible, depending on the mark-up and the mechanisms employed,
    that a system based on fragment identifiers could be used here, and so
    have the browser do all the work whithout and scripting involved.

    Richard.
    Richard Cornford, Feb 18, 2010
    #3
  4. Martin

    Jorge Guest

    On Feb 18, 6:07 pm, Richard Cornford <>
    wrote:
    >
    > If you cannot decide that for yourself what makes you think you are
    > qualified to be designing/building a system like this?


    I guess you were born knowing everything you know now, but we -the
    rest of the people- have had to learn. Sometimes, in the process, we
    ask others for help.
    --
    Jorge.
    Jorge, Feb 18, 2010
    #4
  5. Martin

    Martin Guest

    On Thu, 18 Feb 2010 09:07:21 -0800 (PST), Richard Cornford
    <> wrote:

    >On Feb 18, 4:47 pm, Martin wrote:
    >> I don't know if this is a javascript question or just
    >> html related.

    >
    >If you cannot decide that for yourself what makes you think you are
    >qualified to be designing/building a system like this?
    >
    >> I'm displaying a table of data in a div with overflow set
    >> to "auto" (with a vertical scrollbar being used). Is there
    >> any way I can make it scroll down a certain distance?

    >
    >Scripts can alter the distance by which an overflow auto DIV is
    >scrolled by assigning to the Element's - scrollTop - property
    >(negative values to scroll down) (or - scrollLeft - if left/right
    >scrolling is wanted).
    >
    >> Here's the situation: the user gets the page and he manually
    >> scrolls down into the list. He finds what he's looking for
    >> and then clicks on a row in the table which requests a refresh
    >> of the page with some additional data being shown (elsewhere
    >> on the page). When this refreshed page comes in, I'd like to
    >> automatically scroll him down to where he was when he clicked.

    >
    >In which case scrolling some certain distance requires that you find
    >out that distance in some way (probably reading the current value from
    >the element's - scrollTop - value prior to submitting).
    >
    >It is possible, depending on the mark-up and the mechanisms employed,
    >that a system based on fragment identifiers could be used here, and so
    >have the browser do all the work whithout and scripting involved.
    >
    >Richard.


    Thank you - in spite of the un-needed, snide remark about my
    qualifications.

    I was not aware of the scrollTop property. Learning about it enabled
    me to do exactly what I wanted to.
    Martin, Feb 18, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJ6
    Replies:
    1
    Views:
    4,567
    Henrique Mello
    Jan 9, 2006
  2. UJ
    Replies:
    1
    Views:
    566
    John Timney \(MVP\)
    Nov 1, 2006
  3. Badass Scotsman
    Replies:
    1
    Views:
    178
    Randy Webb
    Apr 27, 2006
  4. yellowtek
    Replies:
    1
    Views:
    169
    Matt Kruse
    Sep 11, 2006
  5. Replies:
    1
    Views:
    113
Loading...

Share This Page