Fixed effects never trigger when using on screen with a width < 1080px
This commit is contained in:
@@ -4,13 +4,19 @@ function RevealOnScroll({ children }) {
|
|||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const isSmallScreen = window.innerWidth < 1080;
|
||||||
|
const observerOptions = {
|
||||||
|
threshold: 0.2,
|
||||||
|
rootMargin: isSmallScreen ? "0px" : "0px 0px -50px 0px"
|
||||||
|
};
|
||||||
|
|
||||||
const observer = new IntersectionObserver(([entry]) => {
|
const observer = new IntersectionObserver(([entry]) => {
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
ref.current.classList.add("visible");
|
ref.current.classList.add("visible");
|
||||||
} else {
|
} else {
|
||||||
ref.current.classList.remove("visible");
|
ref.current.classList.remove("visible");
|
||||||
}
|
}
|
||||||
}, { threshold: 0.2, rootMargin: "0px 0px -50px 0px" });
|
}, observerOptions);
|
||||||
|
|
||||||
if (ref.current) {
|
if (ref.current) {
|
||||||
observer.observe(ref.current);
|
observer.observe(ref.current);
|
||||||
|
|||||||
Reference in New Issue
Block a user