Sitemap
The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Member-only story

Intersection Observer in JavaScript

--

Learn what is intersection observer in JavaScript

Press enter or click to view image in full size
Intersection Observer

Using Intersection Observer we can observe the visibility change of an element(target) in the viewport(screen visible area).

The most important use case of Intersection Observer is Lazy Loading of images. Before Intersection Observer we will be finding the visibility of an element by binding the scroll event and when the scroll event is triggered, you will check if an element in the visible viewport.

From Mozilla :

The Intersection Observer API lets code register a callback function that is executed whenever an element they wish to monitor enters or exits another element (or the viewport), or when the amount by which the two intersect changes by a requested amount. This way, sites no longer need to do anything on the main thread to watch for this kind of element intersection, and the browser is free to optimize the management of intersections as it sees fit.

Steps to use Intersection Observer.

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.