Scrolling to the bottom of a div
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 = d开发者_如何转开发ocument.getElementById("chat");
objDiv.scrollTop = objDiv.scrollHeight;
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.
精彩评论