Last active
December 17, 2015 14:59
-
-
Save johnpolacek/5628794 to your computer and use it in GitHub Desktop.
Lazy Load 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
// <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