dynamic initials

This commit is contained in:
Andrew Gundersen 2021-03-18 15:53:32 -05:00
commit 2b61fbac96
10 changed files with 153 additions and 109 deletions

37
src/modules/scroll.ts Normal file
View file

@ -0,0 +1,37 @@
export default function useScroll(element: string) {
let isScrolledToBottom: boolean;
// Update isScrolledToBottom
const updateScrollRef = () => {
const view = document.getElementById(element)
if (view) {
isScrolledToBottom = view.scrollHeight - view.clientHeight <= view.scrollTop + 1
}
}
// Adjust scroll after we add content to the messenger.
const adjustScroll = () => {
const view = document.getElementById(element)
if (view) {
if (isScrolledToBottom) {
view.scrollTo({
top: view.scrollHeight - view.clientHeight,
behavior: 'smooth'
});
}
}
}
return {
updateScrollRef,
adjustScroll
}
}