Add safezone to scroll end detection to prevent edge cases when scrolling to the end would not detect end (#201)

This commit is contained in:
Valter Martinek
2022-11-26 13:50:53 +01:00
committed by GitHub
parent 12cfc81aa8
commit bfca70a44c
2 changed files with 14 additions and 2 deletions

View File

@@ -20,7 +20,13 @@ const findCurrentPageIndex = (wrapper: HTMLDivElement): number => {
return -1;
};
const isAtEnd = () => window.innerWidth + window.scrollX >= document.body.scrollWidth;
const SCROLL_SAFE_ZONE = 5; // px
const isAtEnd = () => {
const visibleEnd = window.innerWidth + window.scrollX;
// SCROLL_SAFE_ZONE is here for special cases when window might be .5px shorter
// and math just dont add up correctly
return visibleEnd >= document.body.scrollWidth - SCROLL_SAFE_ZONE;
};
const isAtStart = () => window.scrollX <= 0;
export default function HorizontalPager(props: IReaderProps) {