Skip to content
Advertisement

Hide Element on Scrolling in Reactjs?

I have a div that has scrolling enabled for that div. I have some elements in it, when the user starts to scroll I want an element to disappear and when scrolling stops I want it to show up again.

How can I do this

JavaScript

Advertisement

Answer

There is not real scrolling state in the browser; the scrolling event occurs, and then it’s done.

You could set a piece of state called e.g. isScrolling to true when the scrolling event occurs, and then set a timeout to set it back to false after the last time it was scrolled.

Example

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement