Created
April 24, 2018 07:04
-
-
Save chernyshovmaksim/4d57caf2560de227b893581bd493a2ab to your computer and use it in GitHub Desktop.
Функция загрузки изображений при прокрутке
This file contains hidden or 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
| // 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