Skip to content

Instantly share code, notes, and snippets.

View SaurabhGarg1's full-sized avatar
🎯
Focusing

SaurabhGarg1

🎯
Focusing
  • Helsinki, Finland
View GitHub Profile
@SaurabhGarg1
SaurabhGarg1 / setupInterSectionObserver.js
Last active January 20, 2021 05:46
setup intersection observer and execute logic when intersected
const imageObserver = new IntersectionObserver((entries, imgObserver) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const element = entry.target;
element.src = element.getAttribute("dataSrc");
element.removeAttribute("dataSrc");
imgObserver.unobserve(element);
}
});
});