javascript make chat down scrollable automatically
const messages = document.getElementById('messages');
function appendMessage() {
const message = document.getElementsByClassName('message')[0];
const newMessage = message.cloneNode(true);
messages.appendChild(newMessage);
}
function getMessages() {
// Prior to getting your messages.
shouldScroll = messages.scrollTop + messages.clientHeight === messages.scrollHeight;
/*
* Get your messages, we'll just simulate it by appending a new one syncronously.
*/
appendMessage();
// After getting your messages.
if (!shouldScroll) {
scrollToBottom();
}
}
function scrollToBottom() {
messages.scrollTop = messages.scrollHeight;
}
scrollToBottom();
setInterval(getMessages, 100);
Also in JavaScript:
- js change contenteditable value
- check if element has childs jquery
- javascript click button by id
- radio button group get value javascript
- javascript foreach object
- how to disable menu bar in browser using javascript
- tappify.js
- jquery count selected options
- create functional component react
- function click anywhere javascript
- node ubutun
- get css value jquery
- javascript tutorial pdf
- what is 5+5
- how to wait till jquery post request has been made
- downcasting js
- how to stop user from clicking outside alert box js
- javascript convert string to json object
- use property in angular 8
- react native elevation
- node js unix timestamp
- socket io get user rooms
- dart how to convert json to x-www-form-urlencoded
- icon api node js to browser