D
D
deemaagog2018-06-08 08:07:33
React
deemaagog, 2018-06-08 08:07:33

How to catch the scroll to the desired element in React?

Hey! In a react application, there is a long list of elements on the page. How can I catch the scroll to each element of the list? Let's say the scroll can be listened to like this:

componentDidMount() {
    window.addEventListener('scroll', this.handleScroll);
  }

But what's next? how to check that scrolled to the next element?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-06-08
@alexey-m-ukolov

how to check that scrolled to the next element?
Compare the position of the scroll and this element on the page. What is the specific question?
Let's say the scroll can be listened to like this:
componentDidMount() {
    window.addEventListener('scroll', this.handleScroll);
}

It is better to use the Intersection Observer for this , where it is available.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question