Fixed effects never trigger when using on screen with a width < 1080px

This commit is contained in:
Ploc300
2025-02-18 14:19:46 +01:00
parent 01ea3efc11
commit cc55b0c954
+7 -1
View File
@@ -4,13 +4,19 @@ function RevealOnScroll({ children }) {
const ref = useRef(null);
useEffect(() => {
const isSmallScreen = window.innerWidth < 1080;
const observerOptions = {
threshold: 0.2,
rootMargin: isSmallScreen ? "0px" : "0px 0px -50px 0px"
};
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
ref.current.classList.add("visible");
} else {
ref.current.classList.remove("visible");
}
}, { threshold: 0.2, rootMargin: "0px 0px -50px 0px" });
}, observerOptions);
if (ref.current) {
observer.observe(ref.current);