dynamic initials
This commit is contained in:
parent
b7f3d6a858
commit
2b61fbac96
10 changed files with 153 additions and 109 deletions
37
src/modules/scroll.ts
Normal file
37
src/modules/scroll.ts
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue