mime-chat/src/render/composables/useScroll.ts
Andrew Gundersen 531a32a5a5 updated protocols
2021-07-11 11:54:39 -05:00

25 lines
508 B
TypeScript

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