Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple image LazyLoader with jQuery.isOnScreen
var imagesBlock = jQuery('#imagesBlock');
var sliderVisible = imagesBlock.isOnScreen(0, -1); // https://github.com/moagrius/isOnScreen
if (typeof jQuery().isOnScreen === 'function' && !sliderLoaded && sliderVisible) {
var imgs = imagesBlock.find("img");
for(var i = 0; i < imgs.length; i++){
var img = jQuery(imgs[i]);
img.attr("src", img.attr("ref-src")); // replace 'ref-src' attribute with 'src'
}
sliderLoaded = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment