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

27 lines
940 B
JavaScript
Raw Normal View History

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