Auto Scroll with jQuery .animate and AJAX

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

Auto Scroll with jQuery .animate and AJAX

Post by Pazuzu156 »

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:

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');
				}
			}
		});
	}
At one point it worked, now it won't. Any suggestions on how to fix this issue?
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Post Reply