views:

380

answers:

1

As part of an ajax chat room (using prototype framework) I am working on I scroll the user to the bottom each time a message is added using the below js.

However if the user has scrolled up and the list up dates it jumps to the bottom.

Is there any way to detect if the user has scrolled and then disable this function, but also detect when the user is at the bottom again so the js can be re-enabled?

var objDiv = document.getElementById("chat");
 objDiv.scrollTop = objDiv.scrollHeight;
+1  A: 

Before adding the element, check whether objDiv.scrollTop != objDiv.scrollHeight, and, if it's not equal, don't scroll.

Alternatively, you can handle the element's scroll event, check whether objDiv.scrollTop != objDiv.scrollHeight, and, if it is, set a flag to prevent the scroll.

SLaks
What if it isn't scrollable yet?
Pez Cuckow
Then `scrollHeight` will be <= `offsetHeight`; check for that and scroll.
SLaks