1render(){
2 const opacity = Math.min(100 / this.state.currentScrollHeight , 1)
3
4 return <div style={{opacity}} id='element-you-want-to-fade'> </div>
5}
1componentDidMount () {
2 window.onscroll =()=>{
3 const newScrollHeight = Math.ceil(window.scrollY / 50) *50;
4 if (this.state.currentScrollHeight != newScrollHeight){
5 this.setState({currentScrollHeight: newScrollHeight})
6 }
7 }
8}