实际上并不理解为什么此代码部分不能正常工作。该useEffect块在每个滚动位置上重新渲染。另外,我看到这段代码部分:console.log(wrapperRef.current.style.opacity);应该调用 if 和 else if 语句,但事实并非如此。
这是代码:
useEffect(() => {
console.log(wrapperRef.current.style.opacity);
if (wrapperRef.current.style.opacity === 0) {
setIsHidden(true);
console.log("true");
} else if (wrapperRef.current.style.opacity === 1) {
setIsHidden(false);
console.log("false");
}
}, [position]);
Run Code Online (Sandbox Code Playgroud)