Lazyload and CSS background-image property
Opened this issue · 3 comments
DavidPeralvarez commented
Deleted user commented
You don't need this tool to do that, actually. Using jQuery, you can loop through each div (say, with a class of .lazyload). So...
<script>
$('div.lazyload').each(function(){
$(this).css('background-image',$(this).data('img_src'));
});
</script>
<!-- fallback -->
<noscript>
<style>
div.lazyload.image_1 {background-image:url(/path/to/image/1.jpg);}
div.lazyload.image_2 {background-image:url(/path/to/image/2.jpg);}
div.lazyload.image_3 {background-image:url(/path/to/image/3.jpg);}
div.lazyload.image_4 {background-image:url(/path/to/image/4.jpg);}
div.lazyload.image_5 {background-image:url(/path/to/image/5.jpg);}
</style>
</noscript>
<html>
<div class="lazyload image_1" data-img_src="/path/to/image/1.jpg"></div>
<div class="lazyload image_2" data-img_src="/path/to/image/2.jpg"></div>
<div class="lazyload image_3" data-img_src="/path/to/image/3.jpg"></div>
<div class="lazyload image_4" data-img_src="/path/to/image/4.jpg"></div>
<div class="lazyload image_5" data-img_src="/path/to/image/5.jpg"></div>
</html>
DavidPeralvarez commented
Thanks a lot!
akadebnath commented
I tried this, still all the background images are loaded even if they are below the fold. See it here:
http://onedayintime.net/gallery_fasterize.php