fisshy / react-scroll

React scroll component
https://github.com/fisshy/react-scroll/blob/master/README.md
MIT License
4.36k stars 438 forks source link

How can I get notify when one `Element` is scroll out of viewport? #473

Open wenjoy opened 3 years ago

wenjoy commented 3 years ago

Per title, I want to do some extra work when the Element is out of viewport. And I don't need Link to display on the screen, so the Link's onSetActive will not help.

fisshy commented 3 years ago

There are a few events you could subscripe to.

Begin and End events, you could then detect if your element is outside viewport.

 Events.scrollEvent.register('begin', function(to, element) {
      console.log('begin', arguments);
  });

  Events.scrollEvent.register('end', function(to, element) {
    console.log('end', arguments);
  });
wenjoy commented 3 years ago

As I tested, this event only trigger when use scroll method of react-scroll not the scroll of browser. If I understand wrongly, please correct me. What I want to do is notify me when element was scrolled (by mouse or trackpad) out viewport.

Rupenieks commented 2 years ago

Would also like to know. The documentation is vague and the examples not complete.