pleroma-fe/src/components/chat/chat_layout_utils.js

25 lines
925 B
JavaScript
Raw Normal View History

2020-05-07 13:10:53 +00:00
// Captures a scroll position
2022-04-10 16:28:26 +00:00
export const getScrollPosition = () => {
2020-05-07 13:10:53 +00:00
return {
2022-04-10 16:28:26 +00:00
scrollTop: window.scrollY,
scrollHeight: document.documentElement.scrollHeight,
offsetHeight: window.innerHeight
2020-05-07 13:10:53 +00:00
}
}
// 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)
}
2022-04-10 16:28:26 +00:00
export const isBottomedOut = (offset = 0) => {
const scrollHeight = window.scrollY + offset
const totalHeight = document.documentElement.scrollHeight - window.innerHeight
2020-05-07 13:10:53 +00:00
return totalHeight <= scrollHeight
}
// Returns whether or not the scrollbar is visible.
2022-04-10 16:28:26 +00:00
export const isScrollable = () => {
return document.documentElement.scrollHeight > window.innerHeight
}