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-->
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-->
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