Created
January 7, 2015 09:31
-
-
Save cole007/f4664dbd425779577634 to your computer and use it in GitHub Desktop.
Simple lazy load technique
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
<!-- place this at bottom the of your HTML page. it has to be after your images appear in the DOM --> | |
<script> | |
var imgs = document.getElementsByTagName('img'); | |
// var i = 1 skips first instance. use 0 to do all images | |
for (var i = 1; i < imgs.length; i++) { | |
var src = imgs[i].src; | |
imgs[i].setAttribute('data-src',src); | |
// whatever, placeholder image | |
imgs[i].src="hello.jpg"; | |
} | |
</script> |
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
// requires unveil.js | |
// http://luis-almeida.github.io/unveil/ | |
$("img").unveil(200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment