
Intersection Observer API
This API allows our code to basically observe changes to the way that a certain target element intersect another element or the way it intersect the viewport.
const obsCallback = function (entries, observer) {
//this callback function here will get called each time that the observed element (target element) is intersecting the root element at the threshold that we defined
entries.forEach(entry => {
console.log(entry);
});
}
const obsOptions = {
root: null,//Root
//threshold: 0.1 //10%
threshold: [0,0.2] //Will call once section out of veiw or its 20% in view port
};
const observer = new IntersectionObserver(obsCallback, obsOptions);
observer.observe(section1);