const useScrollFadeIn = () => {
const dom = useRef();
const handleScroll = useCallback(([entry]) => {
const { current } = dom;
if(entry.isIntersecting) {
// 원하는 이벤트를 추가 할 것
}
}, []);
useEffect(() => {
let observer;
const { current } = dom;
if (current) {
observer = new IntersectionObserver(handleScroll, { threshold: 0.7 });
observer.observe(current);
return () => observer && observer.disconnect();
};
}, [handleScroll]);
return {
ref: dom,
};
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter