I am creating a chat using Ajax requests and I\'m trying to get messages div to scroll to the bottom without much luck.
I am wrapping everything in this div:
You can use the Element.scrollTo() method.
It can be animated using the built-in browser/OS animation, so it's super smooth.
function scrollToBottom() {
const scrollContainer = document.getElementById('container');
scrollContainer.scrollTo({
top: scrollContainer.scrollHeight,
left: 0,
behavior: 'smooth'
});
}
// initialize dummy content
const scrollContainer = document.getElementById('container');
const numCards = 100;
let contentInnerHtml = '';
for (let i=0; iCard ${i + 1}
.overflow-y-scroll {
overflow-y: scroll;
}