I need some usage examples to accomplish this. I have HTML:
<div id="chatDisplay">
</div>
<input type="text" id="message" /><input type="button" id="send" value="Send" />
Then I have jQuery:
$(function()
{
$('#send').click(function ()
{
$.ajax(
{
url: "chat/postmsg",,
data: { msg: $('#message').val(); },
type: "POST",
success: function (response)
{
$('#chatDisplay').append(response);
}
});
});
});
$(function ()
{
setInterval(function()
{
$.ajax(
{
url: "chat/getupdates",
type: "POST",
success: function (response)
{
}
});
}, 7000);
});
This is just an example of the basic chat features, of course, without server-side code. I need an example of using how to execute what the pseudo code describes. How to determine if the user scrolls to the bottom of the DIV, and how to scroll to the end? I do not want them to jump to the bottom of the DIV if they scroll to see the chat history.
I heard about the JQuery ScrollTo plugin, but you just need some examples.
Thanks in advance!
EDIT: Here is a solution for those interested.
success: function (response)
{
var elem = $('#chatDisplay');
var atBottom = (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight());
$('#chatDisplay').append(response);
if (atBottom)
$('#chatDisplay').scrollTop($('#chatDisplay')[0].scrollHeight);
}
For an example of this in action, go to http://www.jsfiddle.net/f4YFL/4/ .