JSFiddle - React, Tailwind, and code Playground
HTML
<div id="data" style="position: fixed; right: 0; top: 0;"></div>
JavaScript
function jumpToPageBottom() {
$('html, body').scrollTop( $(document).height()-$(window).height());
}
function isAtBottom() {
return $(window).scrollTop() + $(window).height() === $(document).height();
}
var chatNumber = 0;
function startChat() {
var wasAtBottom = isAtBottom();
$("#data").text("Scroll bottom: " + ($(window).scrollTop() + $(window).height()) +
" - Height: " + $(document).height());
$("<div />").text("Message: " + (++chatNumber)).appendTo("body");
if (wasAtBottom) {
jumpToPageBottom();
}
}
setInterval(startChat, 500);