I am currently working on a React app that includes a scrollable div. Here is an example:
<main id="main" onScroll={this.handleScroll}>
My question is, how can I temporarily remove the onScroll event listener from the main element and then reattach it after performing certain actions?
I have two methods of accessing the element:
document.getElementById('main')
and
$('#main')
However, when I inspect the returned element, I cannot seem to find the onScroll property where this.handleScroll is attached. Is there a way to temporarily detach and reattach it?
The reason I need to do this is because I am trying to create a scrollSpy effect. As I navigate through sections in my navbar, I want to scroll the 'main' div accordingly. But since I also use the onScroll event listener on 'main' to detect which section is currently visible, there is a conflict. Therefore, I need to temporarily disable the event listener while interacting with the navbar.