diff --git a/cshare-app/src/hooks/useScrollReveal.js b/cshare-app/src/hooks/useScrollReveal.js new file mode 100644 index 0000000..9d95bb1 --- /dev/null +++ b/cshare-app/src/hooks/useScrollReveal.js @@ -0,0 +1,30 @@ +import { useEffect, useRef } from 'react'; + +export function useScrollReveal(threshold = 0.15) { + const ref = useRef(null); + + useEffect(() => { + const el = ref.current; + if (!el) return; + + const children = el.querySelectorAll('.scroll-reveal'); + if (children.length === 0) return; + + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { + entry.target.classList.add('revealed'); + observer.unobserve(entry.target); + } + }); + }, + { threshold, rootMargin: '0px 0px -40px 0px' } + ); + + children.forEach((child) => observer.observe(child)); + return () => observer.disconnect(); + }, [threshold]); + + return ref; +}