Skip to content

Instantly share code, notes, and snippets.

@chernyshovmaksim
Created April 24, 2018 07:04
Show Gist options
  • Select an option

  • Save chernyshovmaksim/4d57caf2560de227b893581bd493a2ab to your computer and use it in GitHub Desktop.

Select an option

Save chernyshovmaksim/4d57caf2560de227b893581bd493a2ab to your computer and use it in GitHub Desktop.
Функция загрузки изображений при прокрутке
// lazyload
(function () {
var images = document.querySelectorAll('.lazyload');
var options = {
rootMargin: '100px',
threshold: 0.5
}
var callback = function (entries, observer) {
entries.forEach(entry => {
entry.target.setAttribute('src', entry.target.getAttribute('data-original'));
});
}
var observer = new IntersectionObserver(callback, options);
images.forEach(image => {
observer.observe(image);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment