Created
June 12, 2014 18:20
-
-
Save donnielrt/1c862b8aa90e5bf785a5 to your computer and use it in GitHub Desktop.
Lazy loading 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
$(document).ready(function() { | |
$('.load-more').click(function() { | |
$('img.x-lazy').each(function() { | |
var $img = $(this); | |
$img.attr('src', $img.attr('data-original')); | |
}); | |
}); | |
}); |
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
$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