Skip to content
Justice Tech School

Intersection and Resize Observers

IntersectionObserver reports when elements enter the viewport, great for lazy loading and animations. ResizeObserver reports size changes.

Example
const box = document.createElement("div");
box.textContent = "Watch me";
document.body.appendChild(box);
const io = new IntersectionObserver((entries) => {
  entries.forEach((en) => console.log("visible:", en.isIntersecting));
});
io.observe(box);

Exercise

Watch an element.

observer.(el)

Quiz Test

What is IntersectionObserver for?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.