mirror of
https://git.youjo.love/youjo/youjo-fe.git
synced 2024-11-20 05:49:54 +01:00
Will need that, makes sense why it wouldn't compile
This commit is contained in:
parent
12ca73863e
commit
6a5047bf96
1 changed files with 24 additions and 0 deletions
24
src/components/chat/chat_layout_utils.js
Normal file
24
src/components/chat/chat_layout_utils.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Captures a scroll position
|
||||
export const getScrollPosition = () => {
|
||||
return {
|
||||
scrollTop: window.scrollY,
|
||||
scrollHeight: document.documentElement.scrollHeight,
|
||||
offsetHeight: window.innerHeight
|
||||
}
|
||||
}
|
||||
|
||||
// A helper function that is used to keep the scroll position fixed as the new elements are added to the top
|
||||
// Takes two scroll positions, before and after the update.
|
||||
export const getNewTopPosition = (previousPosition, newPosition) => {
|
||||
return previousPosition.scrollTop + (newPosition.scrollHeight - previousPosition.scrollHeight)
|
||||
}
|
||||
|
||||
export const isBottomedOut = (offset = 0) => {
|
||||
const scrollHeight = window.scrollY + offset
|
||||
const totalHeight = document.documentElement.scrollHeight - window.innerHeight
|
||||
return totalHeight <= scrollHeight
|
||||
}
|
||||
// Returns whether or not the scrollbar is visible.
|
||||
export const isScrollable = () => {
|
||||
return document.documentElement.scrollHeight > window.innerHeight
|
||||
}
|
Loading…
Reference in a new issue