Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- var supportsPassive = false;
- try {
- var opts = Object.defineProperty({}, 'passive', {
- get: function() {
- supportsPassive = true;
- }
- });
- window.addEventListener("testPassive", null, opts);
- window.removeEventListener("testPassive", null, opts);
- } catch (e) {}
- window.addEventListener('scroll', lazyload, supportsPassive ? { passive: true, once:true } : false);
- function lazyload(e){
- supportPassive || window.removeEventListener('scroll', lazyload, false);
- var _imgs = document.querySelectorAll('img[data-src],img[data-srcset]');
- for (var i=0; i<_imgs.length; i++) {
- if(_imgs[i].getAttribute('data-src')) {
- _imgs[i].setAttribute('src',_imgs[i].getAttribute('data-src'));
- _imgs[i].removeAttribute('data-src');
- }
- if(_imgs[i].getAttribute('data-srcset')) {
- _imgs[i].setAttribute('srcset',_imgs[i].getAttribute('data-srcset'));
- _imgs[i].removeAttribute('data-srcset');
- }
- }
- }
- })();
Add Comment
Please, Sign In to add comment