mime-chat/src/render/components/control/scroll.js
Andrew Gundersen 5d74c67648 polish
2022-01-18 16:58:56 -06:00

22 lines
No EOL
467 B
JavaScript

let el;
const initScroll = (elementId) => {
el = document.getElementById(elementId);
el.addEventListener('adjust-scroll', adjustScroll);
window.addEventListener('resize', adjustScroll);
}
const isBottom = () => {
return el.scrollHeight - el.clientHeight <= el.scrollTop + 1;
}
const adjustScroll = () => {
if (isBottom()) {
el.scrollTo({
top: el.scrollHeight - el.clientHeight,
behavior: 'smooth'
});
}
}
export default initScroll;