react-scroll icon indicating copy to clipboard operation
react-scroll copied to clipboard

Need some more control over scrollSpy

Open Monkeystation opened this issue 4 years ago • 2 comments

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.

Monkeystation avatar Aug 30 '20 23:08 Monkeystation

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?

fisshy avatar Aug 31 '20 05:08 fisshy

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.

hyzor avatar Oct 07 '20 21:10 hyzor