Created
July 15, 2016 12:52
-
-
Save milosdjakonovic/934c4e249cc34fe687882769cd163f27 to your computer and use it in GitHub Desktop.
Auto lazy load of data-src images
This file contains 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
;(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); |
This file contains 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
!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