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?

首页 - Wiki
Copyright © 2011-2025 iteam. Current version is 2.144.0. UTC+08:00, 2025-07-08 10:27
浙ICP备14020137号-1 $访客地图$