Skip to content

Instantly share code, notes, and snippets.

@johnpolacek
Last active December 17, 2015 14:59
Show Gist options
  • Save johnpolacek/5628794 to your computer and use it in GitHub Desktop.
Save johnpolacek/5628794 to your computer and use it in GitHub Desktop.
Lazy Load Images
// <a href="product.html" data-lazy-image="product.jpg" data-lazy-image-alt="The Product"></a>
;(function($) {
$('*[data-lazy-image]').each(function() {
var alt = $(this).attr('data-lazy-image-alt') === undefined ? '' : 'alt="'+$(this).attr('data-lazy-image-alt')+'"';
$(this).append($('<img src="'+$(this).attr('data-lazy-image')+'" '+alt+'" />'));
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment