469,898 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Return to Previous Position

Howdy,

I know how to tell a DIV with a vertical scroll bar how far to scroll:

document.getElementById( 'myDIV' ).scrollTop += 40;
However, under certain conditions, 'myDIV' is hidden. Upon once again being
visible, I need to return (scroll) to the same position where the user was
before 'myDIV' was hidden. However, I can't figure out how to store the current
position for later retrieval. I've tried using the following:

thePosition = document.getElementById( 'myDIV' ).scrollTop;

But, scrollTop always seems to want to store this value instead:

thePosition = document.body.scrollTop;

Since the main window doesn't have a scroll bar on my screen, scrollTop always
has a value of 0. How do I find the scrolled position of the 'myDIV' instead of
the scrolled position of the body? Since I can set that value, I'm wondering
why I can't retrieve it.

Thanks!
Jim
Jul 23 '05 #1
4 1364
BrassWorld wrote on 25 apr 2004 in comp.lang.javascript:
Since the main window doesn't have a scroll bar on my screen,
scrollTop always has a value of 0. How do I find the scrolled position
of the 'myDIV' instead of the scrolled position of the body? Since I
can set that value, I'm wondering why I can't retrieve it.


<http://www.webreference.com/js/tips/991203.html>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
<< <http://www.webreference.com/js/tips/991203.html> >><BR><BR>
Unfortunately, that page only has information capturing a "window's"
scrollbars. Remember, my browser's window won't have (or need) any scrollbars.
I need information about determining a DIV's scrollbar. The fixed size of this
DIV is smaller than most screen sizes. However, the content inside of that DIV
is scrollable. Once again, my browser window itself will not scroll.

I've already spent a good deal of time on Google trying to find an answer to
this. Since I haven't be able to find an answer to my problem, maybe a good
solution doesn't exist.

Thanks, anyway.
Jim
Jul 23 '05 #3
BrassWorld wrote on 25 apr 2004 in comp.lang.javascript:
<< <http://www.webreference.com/js/tips/991203.html> >><BR><BR>
Unfortunately, that page only has information capturing a "window's"
scrollbars.


You miss the point:

x = document.body.scrollTop

can be changed to

x = document.getElementById("myDivId").scrollTop

To the NS version I cannot help you.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #4
<< You miss the point:

x = document.body.scrollTop

can be changed to

x = document.getElementById("myDivId").scrollTop

To the NS version I cannot help you. >><BR><BR>
That is exactly how I had it written on my first post. [Actually, thePosition =
document.getElementById( 'myDIV' ).scrollTop;] Thanks for confirming that the
initial way I was doing this actually was the correct way. I needed to be
reminded that different browsers do not always respond to a given situation in
the same way.

I was testing my code in Safari on the Mac. It does function (but not real
accurately) with Mozilla on the Mac, but not in Safari. It does, however,
function properly in IE on the Mac. I test with Windows browsers shortly.

Jim
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.