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

M

Martin

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?
 
S

Scott Sauyet

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
 
R

Richard Cornford

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.
 
J

Jorge

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.
 
M

Martin

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


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).


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top