How do I get scrollbar.scrollTo to work on dynamic content? #536
-
I have a chat bot with a scrollable window that doesn't quite scroll to the bottom when new content is added. I am using the following code once a user submits their chat prompt: At this point, an ajax request is sent to the bot, and on completion of that request, I run the above again... however, it seems to stop short of the bottom of the scrollable element, so the response is only partially in view. The ajax request sometimes takes up to 10 seconds to process because it's retrieving the response from OpenAI, however, I am running the above code on 'complete', so it should be able to calculate the new height after the response (i.e., on 'complete'), and then take the user to the bottom of the scrollable element so that the response is fully in view. Could you advise if there is a shortcut to scroll to the bottom in complete, or alternatively advise where I may be going wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi,
You can use
$('#chat_window .scroll-content').append('<div class="chat-local-wrap"><div class="chat-local chats">'+chatData+'</div></div>');
scrollbar.addMomentum(0, size of appnded element) |
Beta Was this translation helpful? Give feedback.
Hi,
smooth-scrollbar
automatically updates itself withResizeObserver
after you append new element to the documentYou can use
addMomentum
append
is synchronous so you can get size of the appended element after You append element