Guest User

Untitled

a guest
Feb 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. (function(){
  2. var supportsPassive = false;
  3. try {
  4. var opts = Object.defineProperty({}, 'passive', {
  5. get: function() {
  6. supportsPassive = true;
  7. }
  8. });
  9. window.addEventListener("testPassive", null, opts);
  10. window.removeEventListener("testPassive", null, opts);
  11. } catch (e) {}
  12. window.addEventListener('scroll', lazyload, supportsPassive ? { passive: true, once:true } : false);
  13. function lazyload(e){
  14. supportPassive || window.removeEventListener('scroll', lazyload, false);
  15. var _imgs = document.querySelectorAll('img[data-src],img[data-srcset]');
  16. for (var i=0; i<_imgs.length; i++) {
  17. if(_imgs[i].getAttribute('data-src')) {
  18. _imgs[i].setAttribute('src',_imgs[i].getAttribute('data-src'));
  19. _imgs[i].removeAttribute('data-src');
  20. }
  21. if(_imgs[i].getAttribute('data-srcset')) {
  22. _imgs[i].setAttribute('srcset',_imgs[i].getAttribute('data-srcset'));
  23. _imgs[i].removeAttribute('data-srcset');
  24. }
  25. }
  26. }
  27. })();
Add Comment
Please, Sign In to add comment