Intersection API
Intersection Observer API
//viewpoint set in options and target set in observe()
//IntersectionObs config can't be changed once set but can observe multiple
let base = useRef()
let target = useRef()
let interObs = useRef();
useEffect(()=>{
let options={
root: base.current, //Document/Element bounding-box used as viewpoint
rootmargin: "0px", //offset margins applied to viewpoint intersections
//interception area percentages that trigger the callback.
threshold: [...Array(100).keys()].map(x => x / 100)
}
//The argument being the observe() target elements
//of which only some are entries[0].isIntersecting
function entered(entries){
console.log( entries[0] )
}
interObs.current = new IntersectionObserver(entered, options)
interObs.current.observe(target.current)
}, [])
Intersection CSS style animation
PreviousJquery & othersNextREACT 1, React props, event handlers, basic useState(), useEffect(), React forms/inputs and Class components
Last updated