I've been trying to update the color of my header when a user scrolls the page, but for some reason, my onScroll
method isn't working. Can anyone help me figure out why and how to solve this issue? The onScroll
method is triggered by the bottom TemplateWrapper
component. And if you have any alternative suggestions on how to achieve this effect, I'm open to them! Thank you!
const headerStyle = {
background: 'grey',
marginBottom: '1.45rem',
position: 'fixed',
top: 0,
left: 0,
width: '100%',
zIndex: '99'
}
const modHeader = () => {
headerStyle.background = 'white'
console.log('scroll')
}
const Header = () => (
<div className='header'
style={headerStyle}
>
<div
style={{
margin: '0 auto',
maxWidth: 1160,
padding: '1.45rem 1.0875rem',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between'
}}
>
<h1 style={{ margin: 0 }}>
<Link
to="/"
style={{
color: 'white',
textDecoration: 'none',
}}
>
Gatsby
</Link>
</h1>
<h2 style={{ margin: 0 }}>
<Link
to="/about"
style={{
color: 'white',
textDecoration: 'none',
}}
>
About
</Link>
</h2>
</div>
</div>
)
const TemplateWrapper = ({
children
}) => (
<div onScroll={modHeader}>
<Helmet
title="Gatsby Default Starter"
meta={[
{ name: 'description', content: 'Sample' },
{ name: 'keywords', content: 'sample, something' },
]}
/>
<Header />
<div
style={{
margin: '0 auto',
maxWidth: 960,
padding: '0px 1.0875rem 1.45rem',
paddingTop: 0,
}}
>
{children()}
</div>
</div>
)
export default TemplateWrapper