Spaces:
Sleeping
Sleeping
Download frontend/src/hooks/useScrollAnimation.ts from moustafa7/protofolio: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/spaces/moustafa7/protofolio/resolve/main/frontend/src/hooks/useScrollAnimation.ts
- Command line
-
hf download hf://spaces/moustafa7/protofolio/frontend/src/hooks/useScrollAnimation.ts
-
curl -L -o useScrollAnimation.ts https://huggingface.co/spaces/moustafa7/protofolio/resolve/main/frontend/src/hooks/useScrollAnimation.ts
594 Bytes
| import { useEffect, useRef, useState } from "react"; | |
| export function useScrollAnimation(threshold = 0.1) { | |
| const ref = useRef<HTMLDivElement>(null); | |
| const [isVisible, setIsVisible] = useState(false); | |
| useEffect(() => { | |
| const observer = new IntersectionObserver( | |
| ([entry]) => { | |
| if (entry.isIntersecting) { | |
| setIsVisible(true); | |
| observer.unobserve(entry.target); | |
| } | |
| }, | |
| { threshold } | |
| ); | |
| if (ref.current) observer.observe(ref.current); | |
| return () => observer.disconnect(); | |
| }, [threshold]); | |
| return { ref, isVisible }; | |
| } | |