Skip to content

Instantly share code, notes, and snippets.

@milosdjakonovic
Created July 15, 2016 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milosdjakonovic/934c4e249cc34fe687882769cd163f27 to your computer and use it in GitHub Desktop.
Save milosdjakonovic/934c4e249cc34fe687882769cd163f27 to your computer and use it in GitHub Desktop.
Auto lazy load of data-src images
;(function(w,d){
var fn=function(){
var body = d.body || d.getElementsByTagName('body')[0];
if(d.querySelectorAll)
var allimgs = d.querySelectorAll('img[data-src]'), allimgs_len = allimgs.length;
for(var i=0;i<allimgs_len;i++){
allimgs[i].setAttribute('src', allimgs[i].getAttribute('data-src'));
}
}
if(w.addEventListener)
w.addEventListener('load', fn, false);
else w.attachEvent('onload', fn);
})(window, document);
!function(t,e){var a=function(){e.body||e.getElementsByTagName("body")[0];if(e.querySelectorAll)var t=e.querySelectorAll("img[data-src]"),a=t.length;for(var r=0;a>r;r++)t[r].setAttribute("src",t[r].getAttribute("data-src"))};t.addEventListener?t.addEventListener("load",a,!1):t.attachEvent("onload",a)}(window,document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment