Skip to content

Instantly share code, notes, and snippets.

@Hibrix-net
Created September 26, 2020 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hibrix-net/7d9774090a76d0e2ce605089fa871128 to your computer and use it in GitHub Desktop.
Save Hibrix-net/7d9774090a76d0e2ce605089fa871128 to your computer and use it in GitHub Desktop.
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