Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. document.addEventListener("DOMContentLoaded", function() {
  2. var lazyImages = document.querySelectorAll('img[lazy-images');
  3. function handlerLazyLoadImages() {
  4. Array.prototype.forEach.call(lazyImages, function(img) {
  5. if ((img.getBoundingClientRect().top <= window.innerHeight && img.getBoundingClientRect().bottom >= 0) && getComputedStyle(img).display != 'none') {
  6. img.setAttribute('src', img.getAttribute('lazy-images'));
  7. img.removeAttribute('lazy-images');
  8. }
  9. });
  10. lazyImages = document.querySelectorAll('img[lazy-images');
  11. }
  12. handlerLazyLoadImages();
  13. document.addEventListener('scroll', handlerLazyLoadImages);
  14. window.addEventListener("resize", handlerLazyLoadImages);
  15. window.addEventListener("orientationchange", handlerLazyLoadImages);
  16. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement