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

Get the Element Name in viewport when scrolling page

Open Filippinifra opened this issue 4 years ago • 1 comments

I'm tryng to create a "scroll spy" effect. The problem is I don't want to use the "Link" component, because my menu work in another way and when I click on menu's item the browser open a new page, and I want to have feedback of what Element I'm watching in the viewport. So there is an api that helps me to know in every moment which element I'm watching on viewport? For example

`

const myComponent = () => {

    const elementWatching = scrollSpy.actualElement;

    return (
       <>
          <Element name="one">
             ...
          </Element>
          <Element name="two">
          ...
          </Element>
          <Element name="three">
             ...
          </Element>
          I'm watching this element: {elementWatching}
       </>
    }
}

`

Thanks, Francesco

Filippinifra avatar Jun 01 '20 15:06 Filippinifra

Hello!

Currently no support for that.

You could add "onSetActive" and "onSetInactive" events on the scroll action.

You could also register global events.

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

fisshy avatar Jun 02 '20 05:06 fisshy