Created
October 29, 2019 12:56
-
-
Save gopalindians/2fff023f8c8f2e8aeef7878b30c8edb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good work