Is it possible in JS to determine whether the image loaded or not?

Is it possible for the customer to determine that the picture has fully loaded, that would be at this event to hang colback
Refinement of the image background, i.e. to determine that the picture on the background is loaded
March 12th 20 at 08:06
1 answer
March 12th 20 at 08:08
Solution
let images = ["image1.jpg", "image2.jpg"];
let promises = [];

images.forEach(function(src) {
 promises.push(new Promise((resolve, reject) => {
 let proxyImage = new Image();

 proxyImage.addEventListener("load", function () {
resolve();
});

 proxyImage.src = src ;
}));
});

Promise.all(promises).then(function () {
 // loaded
});


Can manually specify the paths to the images or to generate automatically ran on all the img elements on a page, or ran on all elements on the page and selecting css properties background-image.

Find more questions by tags JavaScript