Skip to content

Instantly share code, notes, and snippets.

@gopalindians
Created October 29, 2019 12:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gopalindians/2fff023f8c8f2e8aeef7878b30c8edb9 to your computer and use it in GitHub Desktop.
Save gopalindians/2fff023f8c8f2e8aeef7878b30c8edb9 to your computer and use it in GitHub Desktop.
var lazyBackgrounds = [].slice.call(document.querySelectorAll(".lazy-background"));
if ("IntersectionObserver" in window) {
let lazyBackgroundObserver = new IntersectionObserver(function (entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
console.log();
if (entry.target.getAttribute('data-image') === 'universe') {
entry.target.innerHTML = '<img src="images/universe.jpg?v=1" alt="Universe" />';
}
entry.target.classList.add("visible");
lazyBackgroundObserver.unobserve(entry.target);
}
});
});
lazyBackgrounds.forEach(function (lazyBackground) {
lazyBackgroundObserver.observe(lazyBackground);
});
}
@hussain0
Copy link

good work

@hussain0
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment