Animating new item...

Animating new item...

I am making a ajax chat using jquery, and I am trying to animate messages that are new.

  1. $("#submitmsg").click(function(){ var clientmsg = $("#usermsg").val(); $.post("post.php", {text: clientmsg}); $("#usermsg").attr("value", ""); return false; });
  2. function loadLog(){
  3. var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  4. $.ajax({
  5. url: "log.php",
  6. cache: false,
  7. success: function(html){
  8. $("#chatbox").html(html);

  9. var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  10. if(newscrollHeight > oldscrollHeight){
  11.  $('#chatbox').animate({
  12. scrollTop: newscrollHeight
  13.  }, {
  14. duration: 5000, 
  15. complete: function() {
  16.  $(".post:last").animate({opacity: .1}, 1000);
  17. }
  18.  });
  19. }
  20. },
  21. });
  22. }
  23. setInterval (loadLog, 2000);

However, its just constantly animating the last item...  I'm lost...  :(