react滚动到一定位置显示内容
【代码】react滚动到一定位置显示内容。
·
const initState = {
openShow:false,
}
class Header extends Component {
constructor(props) {
super(props);
this.state = initState;
this.activeNavTab=this.activeNavTab.bind(this)
}
componentDidMount= async () =>{
window.addEventListener("scroll", this.activeNavTab, {
passive: true,
});
}
activeNavTab() {
// console.log(window.scrollY);
if (window.scrollY < 245) {
this.setState(() =>({
openShow:false
}))
} else {
this.setState(() =>({
openShow:true
}))
}
}
render() {
// console.log(this.state.nftContract)
return (
<div>
<button onClick={this.backTop} className={ `scroll-top scroll-to-target ${this.state.openShow ? "open" : ""}` }>
<FiArrowUp/>
</button>
</div>
);
}
}
更多推荐
所有评论(0)