Hi WeWeb Community,
I’m currently working on a web app using WeWeb and I’m facing an issue with scrolling a container to the bottom. I want my chatContainerBox
to automatically scroll to the bottom whenever new content is added. However, the solutions I’ve tried so far haven’t worked. Here is the JavaScript code I am using:
setTimeout(function() {
var element = wwLib.getFrontDocument().getElementById(‘chatContainerBox’);
if (element) {
// Scroll to the bottom by setting scrollTop
element.scrollTop = element.scrollHeight;
} else {
console.error(‘Message container not found’);
}
}, 0);
I have also tried using scrollIntoView
, but it didn’t work either. Here is that code for reference:
var element = wwLib.getFrontDocument().getElementById(‘chatContainerBox’);
if (element && element.lastElementChild) {
element.lastElementChild.scrollIntoView({ behavior: “smooth”, block: “end” });
} else {
console.error(‘Message container or its last element not found’);
}
Despite these attempts, the container does not scroll to the bottom as expected. I could manage to scroll into top, but not to botton.
I tried to follow all the suggestions on other topics but I could not manage to work.
My message container (chatContainerBox) is on display flex.
Does anyone can help me?