Created
December 2, 2016 16:00
-
-
Save turbopixel/5b01f6bee5f221bb2984ea5e702dc409 to your computer and use it in GitHub Desktop.
Load images after document-ready. Write image source in "data-src" and call the function lazyLoad('#parent-div");
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
/** | |
* Set image data-src="" to src="" | |
* @author Nico Hemkes <www.hemk.es> | |
* | |
* @param parent jQuery selector | |
*/ | |
function lazyLoad( parent ){ | |
var images = $(parent).find('img'); | |
$.each( images, function( i, img ){ | |
var src = $(img).data('src'); | |
// check if img set | |
if(src.length == 0){ | |
return; | |
} | |
// show image | |
$(img).attr('src', src); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment