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