Intersection Observer API

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);

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment