I want to when scroll down 100px , add body className="showdiv"
on gatsby react.
How can I do this?
I try this code:
state = {
isTop: true,
};
componentDidMount() {
document.addEventListener('scroll', () => {
const isTop = window.scrollY < 100;
if (isTop !== this.state.isTop) {
this.setState({ isTop })
}
});
}
classname
{this.state.isTop ? 'down' : 'up'}
But I can't add body class. I want to new and simple idea..
Thanks