Make caching of scroll position more robust

Previously, the scroll position was only updated on a scroll event, but
this fails to update properly if the element goes from being hidden to
visible, or if the window is resized. The scroll position is now cached
before its use in finding which pages are visible. The purpose remains
the same since the DOM only needs to be accessed once rather than for
each page.