Skip to content

Instantly share code, notes, and snippets.

@bdougherty
Created May 15, 2009 21:30
Show Gist options
  • Save bdougherty/112448 to your computer and use it in GitHub Desktop.
Save bdougherty/112448 to your computer and use it in GitHub Desktop.
// Figure out heights and things
var chat = document.getElementById('chat_space');
var currentScrollPos = chat.scrollTop;
var maxScrollPos = chat.scrollHeight - chat.clientHeight;
var scrolled = (currentScrollPos == maxScrollPos) ? true : false
// Clear out the box and replace with data from ajax
// Should we scroll?
if (scrolled) chat.scrollTop = chat.scrollHeight;
else chat.scrollTop = currentScrollPos;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment