Page 1 of 1

Ajax help auto scroll to bottom

Posted: Thu Mar 31, 2011 3:55 am
by Klown
i am completely new to ajax, i found a small section of code on the net. I modified it to auto scroll to bottom during an interval. but i wish for user to have the ability to scroll up and content to still load without forcing to bottom. so if user is at bottom force bottom, if user is scrolling, dont force bottom just load content as usual.

this is for a simple chat script im making for my game.

Code: Select all

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
   setInterval(
   function(){
   $('#chat').load('loadchat.php');
   $("#chat").attr({ scrollTop: $("#chat").attr("scrollHeight") });
   }, 100);
</script>
the original script i found did not include: $("#chat").attr({ scrollTop: $("#chat").attr("scrollHeight") });
i added that in. so that it would scroll to bottom.

any suggestions would be appreciated.

-klown