homebrewery icon indicating copy to clipboard operation
homebrewery copied to clipboard

Use IntersectionObserver to detect current page

Open G-Ambatte opened this issue 5 months ago • 3 comments

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 the pageArray 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).

G-Ambatte avatar Aug 29 '24 03:08 G-Ambatte