View Full Version : Vertical scrolling in a DIV

10-07-2003, 10:45 AM
I use a DIV element to display a tree. The tree looks like the Window Explorer, with folders and +/- to go up or down in the tree. I use overflow: auto; to get scrollbars if the tree gets to big for the DIV.
My problem is:
I scroll down to a line and press for example + ,
the screen refreshes with data from my servlet. And the scrollbar starts at the top again.
I want to have position of the scrollbar at the point I was before the update.

10-08-2003, 10:00 AM
Try using DHTML scrolling methods scroll(x,y) or scrollTo(x,y) within an ID idetified object (your DIV)...

Try document.getEmentntById(id).scrollTo(x,y)

I haven't tasted but it might work

10-08-2003, 10:02 AM

10-08-2003, 02:06 PM
Thanks for the tip.
I use document.getElementById("id").scrollLeft = x
and document.getElementById("id").scrollTop = y
instead of scrollTo(x,y).
It seems to work.


10-13-2003, 10:37 PM
Will this work w/ both NS6 and IE6? (only have one at work, but need to account for both eventually)

10-14-2003, 07:08 AM
I have not tested in NS6 but I use the following:

var isIE = 0;
if( navigator.appName.indexOf('Microsoft Internet Explorer') != -1 ){isIE = 1;}

function scrollDIVTo(x,y){
if( isIE ){
document.getElementById("liste").scrollLeft = x;
document.getElementById("liste").scrollTop = y;
scrollTo( x,y );


10-15-2003, 02:22 AM
I'm trying to scroll an element of a DIV into view.
Ive got a table with 40 rows within a scrollable div.

I tried

div.scrollTop = node.offsetTop

where node is a table cell within a scrollable div.
This works fine as long as the node is not close to the bottom of the table. But if the node is < div.clientHeight from the end of the div, the div.clientHeight is reduced. Its really crazy.

(I know node.offsetTop is the offset from the top of the table. There's nothing between the top of the table and the top of the div). I noticed that there's a scrollIntoView method, but unfortunately it scrolls the entire page and not just the div content. Has anyone done something like this?