This commit is contained in:
Your Name committed 2026-06-29 19:51:04 -04:00
1 parent 9922e8a5bc
commit 0144545166
4 files changed
+197 -16

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
"use client"
import { useEffect, useRef, useState } from 'react';
interface UseScrollRevealOptions {
threshold?: number;
rootMargin?: string;
once?: boolean;
}
export function useScrollReveal<T extends HTMLElement = HTMLDivElement>(
options: UseScrollRevealOptions = {}
) {
const { threshold = 0.1, rootMargin = '0px 0px -60px 0px', once = true } = options;
const ref = useRef<T>(null);
const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setIsVisible(true);
if (once) observer.disconnect();
} else if (!once) {
setIsVisible(false);
}
},
{ threshold, rootMargin }
);
observer.observe(el);
return () => observer.disconnect();
}, [threshold, rootMargin, once]);
return { ref, isVisible };
}