Spaces:
Build error
Build error
Create handleAutoScrollChat.js
Browse files- handleAutoScrollChat.js +18 -0
handleAutoScrollChat.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function Scrolldown() {
|
| 2 |
+
let targetNode = document.querySelector('#chatbox-container');
|
| 3 |
+
|
| 4 |
+
if (!targetNode) {
|
| 5 |
+
console.error('Chat container not found');
|
| 6 |
+
return;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
const config = { childList: true, subtree: true };
|
| 10 |
+
|
| 11 |
+
const callback = (mutationList, observer) => {
|
| 12 |
+
targetNode.scrollTop = targetNode.scrollHeight;
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
const observer = new MutationObserver(callback);
|
| 16 |
+
|
| 17 |
+
observer.observe(targetNode, config);
|
| 18 |
+
}
|