Jump to content

SCrollbar


jaymc

Recommended Posts

Ok, I have a ajax chatroom, Im trying to control the scroll bar to do the following

 

1: Push the scroll bar to the very bottom of the page on each load

Code = objDiv.scrollTop = objDiv.scrollHeight+900;

 

That part is working fine, apart from a small bug in IE where sometimes it only goes half way down the page

 

However, my problem is.. if someone in the chatroom wants to scroll up and read old posts, after 4 seconds my little javascript will scroll them straight back down!

 

Im trying to combat that by on each 4 second refresh, detect the scroll bars current position, and if its not at the bottom or withing 10px from the bottom it wont bother doing my objDiv.scrollTop

 

So basically..

 

if (scroll_bar_has_been_moved_by_user) {Dont do objDiv.scrollTop} else {objDiv.scrollTop}

 

To go on further, Ive actually compiled some code that will do just that.. but theres a problem

 

var intY = document.getElementById("divExample").scrollTop;

var intE = document.getElementById("divExample").scrollHeight;

 

Basically, im checking intY and seeing if its equal to intE, if it is, then we know the scroll bar is at the bottom and hasnt been moved... great!

 

However, intY does not equal intE when its at the bottom, ive done some testing and it appears the 'SCROLLBAR' takes up some hight which is not taken into account by scrollTop

 

So, if scrollHeight is equal to 3500 which is the max scrollable height, even if the scrollbar is positioned right at the very bottom, it will only equal around 3200

 

The bigger the actual physical scrollbar, the more distance between scrollHeight and scrollTop

 

I hope Ive explained well, this is driving me mad!

 

 

So just to recap incase theres an easier way.. I want my scroll bar at the bottom of the page all the time, unless, the user moves it them selves. If they do it will stop scrolling auto until they place the scroll bar back at the bottom

 

Please help!

Link to comment
Share on other sites

This might help you:

http://www.quirksmode.org/js/doctypes.html

 

Because the size of the scrollbars are supposed to be proportional to: (window size)/(total doc length), wouldn't it be true that the difference between the scrollheight and the scrollbar at the bottom would be the window height minus chrome?

 

(scrollbar at bottom) + windowheight = scrollheight

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.