Auto Scroll with jQuery .animate and AJAX
Posted: Sat Dec 31, 2011 12:10 am
I'm building a web based chat thing, and i have it where when the new message comes up, it will auto scroll down to show that message, to prevent the user from having to scroll down manually.
This is my jQUery:
At one point it worked, now it won't. Any suggestions on how to fix this issue?
This is my jQUery:
Code: Select all
function loadLog() {
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
$.ajax({
url: "./assets/log.php",
cache: false,
success: function(html) {
$("#chatbox").html(html);
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight) {
$("#chatbox").animate({scrollTop: newscrollHeight}, 'normal');
}
}
});
}