Detect if objects are loaded [Javascript]

I was wondering if there is a way to determine if a specific image / div is loaded? For example, when I upload two heavy images and show the download sign in two places that will then occupy the images, is there a way to already display the first image when it loads when the second loads?

+2
source share
3 answers
myImage.addEventListener('load', function() { ... }, false);

Code inside the specified function will be called when the image is completed.

+1
source

If you use new Imageto preload images, you can do the following to receive a notification that it has been downloaded

var img = new Image();
img.onload = function() {
    //display the image
    document.getElementById("myDiv").innerHTML = "%3Cimg src='myimg.jpg' alt=''/%3E";
};
img.src = "myimg.jpg";

src onload.

+1

if the image is uploaded, its property .completeswitches to true.

0
source

Source: https://habr.com/ru/post/1763005/


All Articles