homebrewery
homebrewery copied to clipboard
Use IntersectionObserver to detect current page
This PR uses the IntersectionObserver to detect which page elements are in the viewport and thus visible to the end user. This data is updated as the user scrolls, and is passed to a new function updatePageArray
in helpers.js
.
This PR also adds two further new functions to helpers.js
:
-
getPageNumber
: returns an integer, the average value of the content of thepageArray
which should be the most central page in the range of visible pages -
getVisiblePageRange
: returns a string, if the array length is 3 or less, joined by commas (e.g.1, 2, 3
) and for lengths greater than 3, the first and last page separated by a dash (e.g.1 - 5
).