logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

chat_layout_utils.js (925B)


  1. // Captures a scroll position
  2. export const getScrollPosition = () => {
  3. return {
  4. scrollTop: window.scrollY,
  5. scrollHeight: document.documentElement.scrollHeight,
  6. offsetHeight: window.innerHeight
  7. }
  8. }
  9. // A helper function that is used to keep the scroll position fixed as the new elements are added to the top
  10. // Takes two scroll positions, before and after the update.
  11. export const getNewTopPosition = (previousPosition, newPosition) => {
  12. return previousPosition.scrollTop + (newPosition.scrollHeight - previousPosition.scrollHeight)
  13. }
  14. export const isBottomedOut = (offset = 0) => {
  15. const scrollHeight = window.scrollY + offset
  16. const totalHeight = document.documentElement.scrollHeight - window.innerHeight
  17. return totalHeight <= scrollHeight
  18. }
  19. // Returns whether or not the scrollbar is visible.
  20. export const isScrollable = () => {
  21. return document.documentElement.scrollHeight > window.innerHeight
  22. }