25 lines
508 B
TypeScript
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);
|
|
|
|
}
|