I want to change background color of my navbar section on scroll, I could try but its never work.
My code here.
const [colorChange, setColorChange]=useState(false)
const changeColor=()=>{
if(window.scrollY >=120){
setColorChange(true)
}
else{
setColorChange(false)
}
}
CodePudding user response:
If that's the whole code you have then it seems that changeColor
method is never executed. You have to bind it with onScroll
event
CodePudding user response:
If that's the whole code you have then it seems that changeColor method is never executed. You have to bind it with onScroll event