useIntersectionObserver

当元素进入其父元素的视口时,执行回调函数。


import { useIntersectionObserver } from 'primereact/hooks';
         

滚动父元素以查看子元素。

不可见

const elementRef = useRef(null);
const visible = useIntersectionObserver(elementRef);
         

threshold 选项定义了元素应该可见的百分比,例如,0.5 表示至少一半的元素。

不可见

const elementRef = useRef(null);
const visible = useIntersectionObserver(elementRef, { threshold: 0.5 });