我有一个if条件,在满足条件下,我想将状态设置为true,否则将状态设置为false。
componentDidMount = () => {
document.onscroll = () => {
var light_pos = document.getElementById('mobileApp').offsetTop;
var light_height = document.getElementById('mobileApp').offsetHeight;
var menu_pos = $('#text').offset().top;
var scroll = window.scrollY;
if (menu_pos > light_pos && menu_pos < (light_pos + light_height)) {
document.getElementById('text').classList.add('colorRed')
/*set state here */
}
if((scroll === 0) || (scroll > 1350)) {
document.getElementById('text').classList.remove('colorRed')
/*set state here */
}
}
}