react-scroll
react-scroll copied to clipboard
Need some more control over scrollSpy
My issue is that scrollSpy only triggers when the element reaches the top of the window, but I would actually like to trigger it when the top of the element is at 50% of the window height. This makes more sense to me as the element is now visible to the user. A separate scrollSpy offset would do the trick.
Wouldn't it be possible to set the offset dynamically as you scroll?
i.e calculate the center of the window, and set that as the offset?
I had a similar issue and solved it by removing the spy functionality completely from my <Link>
elements and introduced <Waypoint>
elements instead from the wonderful react-waypoint library.
That way I could still keep the smooth scrolling functionality of react-scroll that will scroll to my elements wrapped with <Waypoint>
with offsets of 40%, in turn this will trigger the waypoint onEnter
function, thus replacing spy
and onSetActive
from this lib.