如何将jQuery卷轴代码转换为reactjs?
if($(".app-wizard-header").length > 0) {
if ($(document).scrollTop() > 50) {
this.setState({Headerbg:'app-wizard-header'})
} else {
this.setState({Headerbg:'app-wizard-header no-bg'})
}
}
答案:
import ReactDOM from 'react-dom';
var node = ReactDOM.findDOMNode(this.refs.Headerbg);
if (node){
if (window.scrollY > 50) {
this.setState({...});
} else {
this.setState({...});
}
}