I have two images on my html page and i'm using jquery to check when they are fully loaded before removing the circle loader overlay (individually for each image). So at the beginning the overlay with the loader animation is shown on each pictures, and every time a picture is loaded the overlay is toggled off. But with my current code the overlay is not toggled off at all.
<div class="img" id="img1">
<div class="image-loader">
<div class="cssload-speeding-wheel"></div>
</div>
</div>
<div class="img" id="img2">
<div class="image-loader">
<div class="cssload-speeding-wheel"></div>
</div>
</div>
$(document).ready(function(){
$('.img').each(function(){
let img = $(this).css('background-image').replace('url(','').replace(')','').replace(/\"/gi, "");
$('<img/>').attr('src', img).on('load', function() {
$('#' + $(this).attr('id') + ' .image-loader').hide();
});
});
});
The code was working for a single image:
$(document).ready(function(){
let img = $('#img1').css('background-image').replace('url(','').replace(')','').replace(/\"/gi, "");
$('<img/>').attr('src', img).on('load', function() {
$('#img1 .image-loader').hide();
});
});
Does anyone have a solution for this? thanks