const nav1=document.querySelector('.navbar');
window.addEventListener('scroll',
function ()
{
if(window.scrollY>70)
{
nav1.classList.add('new_nav');
}
else if (window.scrollY < 69)
{
nav1.classList.remove('new_nav');
}
}
Im trying this code in React App.js file, if i scroll down it shows error like "nav1 is NULL".It worked when it was a html,js file.
If i scroll the class file need to change.
2
Answers
events are handled a bit differently in ReactJS.I’ll suggest you read through React docs as well ReactJS Docs
I’ve attached a solution here solution
Can you give us more Content from your React File or Function?