-2

I have a div which is a chat window. As people send messages and they are appended to the end of the content I want the content to scroll to the bottom (so the latest chat message is visible).

<div id="chat">

</div><!--chat end-->
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
southpaw93
  • 1,891
  • 5
  • 22
  • 39

2 Answers2

0

You can use jQuery.scrollTop().

http://api.jquery.com/scrollTop/

Hope it helps.

Lucas Lazaro
  • 1,516
  • 9
  • 13
0

You can animate the CSS value scrollTop to the content height (or scrollHeight) of the container.

Here is the example code and I've used it in this fiddle: http://jsfiddle.net/aHx2Z/

// get the new height of the chat window
var height = $('#chat_window')[0].scrollHeight;
$('#chat_window').animate({scrollTop:height}, 1000); // you could use .css() instead if you don't want it to animate
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224