JQuery chat application scroll to bottom of div ONLY on new message?
This question shows research effort; it is useful and clear
0
This question does not show any research effort; it is unclear or not useful
Show activity on this post.
I have picked up this AJAX code from multiple tutorials, but the problem is, when the ajax is called, the div ALWAYS scrolls to the bottom. But I want it so that the div ONLY scrolls if there are new messages in the div.
$.ajax({ url: "msg-handle/get-messages.php", cache: false, data: { room: $("#room").val() }, success: function(data) { $('#chat').html(data) $("#chat").scrollTop($("#chat")[0].scrollHeight); },
}); }, 500);
Is there a way to achieve this without any major ramifications to my code?