Skip to content

Instantly share code, notes, and snippets.

@bencooling
Created June 12, 2014 10:33
Show Gist options
  • Save bencooling/62470207a14d3c6ca0b5 to your computer and use it in GitHub Desktop.
Save bencooling/62470207a14d3c6ca0b5 to your computer and use it in GitHub Desktop.
Javascript Lazy Load Images
<!-- markup -->
<img data-src="/image/to/lazy/load.jpg" src="" />
<script type="text/javascript">
lazyLoad : function($images){
$images.each(function(i, el){
var $el = $(el);
if (!el.loaded){
$el.attr('src', $el.attr('data-src'));
el.loaded=1;
}
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment