Jquery 如何更改react.js中滚动条上导航栏的背景和文本颜色?
我正在尝试在react.js中添加一个透明的导航栏,现在我想更改滚动条上导航栏的背景和文本颜色Jquery 如何更改react.js中滚动条上导航栏的背景和文本颜色?,jquery,css,reactjs,Jquery,Css,Reactjs,我正在尝试在react.js中添加一个透明的导航栏,现在我想更改滚动条上导航栏的背景和文本颜色 <div className="logo"> <a href='/'> <img alt='logo' src={require('./images/local/Wings-Logo-512.png')}/> </a> </div> scoll上的背景色应更改。应使用window.s
<div className="logo">
<a href='/'>
<img alt='logo' src={require('./images/local/Wings-Logo-512.png')}/>
</a>
</div>
scoll上的背景色应更改。应使用window.scrollY进行修复
const [navBackground, setNavBackground] = useState(false)
const navRef = useRef()
navRef.current = navBackground
useEffect(() => {
const handleScroll = () => {
const show = window.scrollY > 670
if (navRef.current !== show) {
setNavBackground(show)
}
}
document.addEventListener('scroll', handleScroll)
return () => {
document.removeEventListener('scroll', handleScroll)
}
}, [])
//then
<Navbar
backgroundColor={navBackground ? 'white' : 'transparent'}
style={{ transition: '1s ease' }}
/>
const[navBackground,setNavBackground]=useState(false)
const navRef=useRef()
navRef.current=navBackground
useffect(()=>{
常量handleScroll=()=>{
const show=window.scrollY>670
如果(导航参考当前!==显示){
setNavBackground(显示)
}
}
文档.添加的文本列表器(“滚动”,把手滚动)
return()=>{
document.removeEventListener('scroll',handleScroll)
}
}, [])
//然后