Skip to content

Instantly share code, notes, and snippets.

@donnielrt
Created June 12, 2014 18:20
Show Gist options
  • Save donnielrt/1c862b8aa90e5bf785a5 to your computer and use it in GitHub Desktop.
Save donnielrt/1c862b8aa90e5bf785a5 to your computer and use it in GitHub Desktop.
Lazy loading images
$(document).ready(function() {
$('.load-more').click(function() {
$('img.x-lazy').each(function() {
var $img = $(this);
$img.attr('src', $img.attr('data-original'));
});
});
});
$imgList.find('img').each(function(i, img) {
// Note: image resizing is disabled by client request due to caching issues
// load the first 4, but lazy load the rest
img.setAttribute('data-original', img.getAttribute('x-src')); // save the image URL to data-original for lazy loading
img.className += ' x-lazy';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment