Skip to content

Instantly share code, notes, and snippets.

@turbopixel
Created December 2, 2016 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turbopixel/5b01f6bee5f221bb2984ea5e702dc409 to your computer and use it in GitHub Desktop.
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");
/**
* 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