Skip to content

Instantly share code, notes, and snippets.

@fabioluzm
Created September 16, 2019 14:29
Show Gist options
  • Save fabioluzm/ce93b4c9e72567cd77d3b2268a2bda93 to your computer and use it in GitHub Desktop.
Save fabioluzm/ce93b4c9e72567cd77d3b2268a2bda93 to your computer and use it in GitHub Desktop.
Delayed loader for images
// you need on the HTML to set the img url into the data-src, and the pre-load img(gif) on the src
// function below gets your data-src info and set it on the src attribute after 1500ms
window.setTimeout(function() {
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var currImage = images[i];
if (currImage.getAttribute('data-src')) {
currImage.setAttribute('src', currImage.getAttribute('data-src'));
}
}
}, 1500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment