Skip to content

Instantly share code, notes, and snippets.

@JRaspass
Created June 24, 2019 09:22
Show Gist options
  • Select an option

  • Save JRaspass/da6d2c843e3a908ad591ae9dd8925b69 to your computer and use it in GitHub Desktop.

Select an option

Save JRaspass/da6d2c843e3a908ad591ae9dd8925b69 to your computer and use it in GitHub Desktop.
'use strict';
const imgs = document.querySelectorAll('[data-src]');
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(entries => {
for (const entry of entries)
if (entry.isIntersecting) {
entry.target.src = entry.target.dataset.src;
observer.unobserve(entry.target);
}
});
imgs.forEach(e => observer.observe(e));
}
else
imgs.forEach(e => e.src = e.dataset.src);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment