Skip to content

Instantly share code, notes, and snippets.

@dented
Last active September 2, 2015 08:17
Show Gist options
  • Select an option

  • Save dented/38e88af4fe5efba74b30 to your computer and use it in GitHub Desktop.

Select an option

Save dented/38e88af4fe5efba74b30 to your computer and use it in GitHub Desktop.
Lazy Load Images trials
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