Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lazy Loading Images w/ jQuery
<div class="lazyImage" data-src="http://baconmockup.com/200/200" data-width="200" data-height="200" data-title="Mmmm Bacon"></div>
$(function() {
var b, e;
b = $(window);
e = $('.lazyImage');
b.scroll(function() {
$.each(e, function() {
var c = $(this), a, d;
a = c.offset();
d = c.data();
if(!d.loaded && a.top <= b.height() + b.scrollTop()) {
a = new Image, $.extend(a, d), a.onload = function() {
c.prepend(this);
$(this).fadeIn();
c.removeClass('lazyImage');
e = $('.lazyImage')
}, c.data('loaded', !0)
}
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.