Created
September 16, 2019 14:29
-
-
Save fabioluzm/ce93b4c9e72567cd77d3b2268a2bda93 to your computer and use it in GitHub Desktop.
Delayed loader for 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
// 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