Created
September 26, 2020 14:04
-
-
Save Hibrix-net/7d9774090a76d0e2ce605089fa871128 to your computer and use it in GitHub Desktop.
Simple image LazyLoader with jQuery.isOnScreen
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
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