I am trying to add a class when the top of the window scrolls to a specific ID and removes class when scrolls back to the top. i am new to ReactJs and unsure how to accomplish this.
window.onscroll = function() {scrollFunction()};
scrollFunction() {
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
document.getElementById("myID").className = "test";
} else {
document.getElementById("myID").className = "";
}
}
how can i use something like this in React? looking for a simple function that will handle this
<a href="#somethin"clicking this link it'll navigate inside the page!