Last active
September 2, 2015 08:17
-
-
Save dented/38e88af4fe5efba74b30 to your computer and use it in GitHub Desktop.
Lazy Load Images trials
This file contains hidden or 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
| var images = document.querySelectorAll('img[data-src]'), | |
| imageLength = images.length; | |
| Array.prototype.forEach.call(images, function(image) { | |
| image.setAttribute('src', image.getAttribute('data-src')); | |
| image.onload = function() { | |
| image.removeAttribute('data-src'); | |
| }; | |
| }); | |
| for(var i = 0;i<images.length;i++) { | |
| var image = images[i]; | |
| image.setAttribute('src', image.getAttribute('data-src')); | |
| image.onload = function() { | |
| image.removeAttribute('data-src'); | |
| }; | |
| } | |
| for(var i = 0;i<imageLength;i++) { | |
| var image = images[i]; | |
| image.setAttribute('src', image.getAttribute('data-src')); | |
| image.onload = function() { | |
| image.removeAttribute('data-src'); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment