desandro / imagesloaded

:camera: JavaScript is all like "You images done yet or what?"
https://imagesloaded.desandro.com
MIT License
8.88k stars 1.15k forks source link

Background load is not detected. Always calls the 'isLoaded' callback. #270

Open WhereJuly opened 6 years ago

WhereJuly commented 6 years ago

Hello,

thanks for the great piece of the code of yours :100:

Though I found imagesloaded, while in the background mode does not detect if the image is loaded. Either it is or it is not, or even when the element does not have any background, the callback function signals in all the cases that the bg is loaded.

Here is the reduced test case on CodePen based on your recommended example.

Can you please kindly check and fix this or tell if I do something wrong?

Thanks again, Val

WhereJuly commented 6 years ago

Well, after deeper look into the documentation I found the source of the issue.

The documentation is contradictory saying Using a callback function is the same as binding it to the always event (see below). assuming that the callback is called in any case, either load was successful or not, and the example below saying #container background image loaded

// vanilla JS
imagesLoaded( '#container', { background: true }, function() {
  console.log('#container background image loaded');
});

Probably better to change the last phrase into something #container background image loading process ended with either success or fail

WhereJuly commented 6 years ago

Then there is still another issue when the pattern used in the documentation to detect the image is loaded

// vanilla JS
imgLoad.on( 'done', function( instance ) {
  console.log('DONE  - all images have been successfully loaded');
});

calls the done callback not only on actually successful image load but even when the element does not have any background set.

The test case is at the link in my first message here.

desandro commented 6 years ago

Thanks for reporting this issue. I'll have to take a look.

Michas0206 commented 6 years ago

Same problem here. Why is it still not being fixed? This plugin is completely useless - it runs my function even if the picture is not loaded (or also if there is no picture at all or the complete div does not exist).

shockthetoast commented 5 years ago

I can confirm that this is not working for background images. It is triggering "done" long before the image actually loads. I am dynamically creating a number of DIVs and applying a "background-image" to each. If I use Chrome's developer tools to set "Fast 3G", there are a few seconds between "done" triggering and the images finishing to load/displaying.