Items
<img> have an onload that fires after the image is fully loaded. Therefore, in js, you can track the number of images uploaded and the number of remaining with this event.
Images also have the corresponding onerror and onabort , which are triggered when the image does not load or the download was interrupted (the user clicked the "x" button). You also need to track them along with the onload in order to properly track the loading of images.
Additional answer:
A simple example in pure js:
var img_to_load = [ '/img/1.jpg', '/img/2.jpg' ]; var loaded_images = 0; for (var i=0; i<img_to_load.length; i++) { var img = document.createElement('img'); img.src = img_to_load[i]; img.style.display = 'hidden';
The above example does not handle onerror or onabort for clarity, but real-world code should also take care of them.
slebetman
source share