hsunpei / react-scrolly

Scroll-based interactions made easy.
https://hsunpei.github.io/react-scrolly/
22 stars 2 forks source link

react-scrolly

Scrolly-telling made easy

Magical scroll-based interactions made easy with react-scrolly.

Scroll-based interactions create an incredible experience by letting users explore the story with simple scrolls, such highlighting a portion of the content, or animating the route on a map based on the position of the section user is reading.

However, tracking the scrolling progress by yourself is burdensome, and binding the window scroll tracking for each component is prone to cause performance issues as the number of tracked components increase, and thus making users see the screen juddering when scrolling.

With this in mind, react-scrolly is created to allow you to track the progress of scrolling with minimum efforts and the performance impact.

react-scrolly is perfect for the following use cases:

Definition of the scrolled ratio

The scrolled ratio is defined by the ratio of a component being scrolled over the bottom of the screen (viewport).

Scrolled ratio

Why is it performant?

In contrast to the traditional scroll tracking by binding window scroll event listeners to components and calling getBoundingClientRect() on scroll which potentially causes many unnecessary re-renderings and reflows, react-scrolly only notifies the scrolling position changes to the components currently intersected with the viewport, which is made possible by utilizing the IntersectionObserver, RxJS, the context API, and React hooks.

How to design scrolly-telling

Here are some references to help you design better scrolly-telling: