javascript - Is there a way to know when all the images have been downloaded from the server? -


this question has answer here:

i have simple html page want load stack of images. , want display 1 of them according user's cursor on screen. i'm trying :

http://test.vostrel.net/jquery.reel/example/object-movie-camera-sequence/

i in 2 steps, in first 1 load low resolution images (60 images in less 2 seconds) , in second 1 when user click first time swap low res high resolution images (60 images in 10 seconds).

those 2 functions :

function loadimages() {     var imagesdom;     (var j = 0 ; j < directoriesnumber ; j++) {         imagesdom = new array();         (var = 1 ; < imagenumber + 1 ; i++) {             images[i] = imagedirectory[j] + "/" + imagebasename + twodigits(i) + imageextension;         }         (var = 1 ; < imagenumber + 1 ; i++) {             imagesdom[i] = new image();             imagesdom[i].id = "image" + j + "_" + i;             imagesdom[i].src = images[i];             $("#cadre").append(imagesdom[i]);         }     } }  function loadimageshigh() {     (var j = 0 ; j < directoriesnumber ; j++) {         (var = 1 ; < imagenumber+1 ; i++) {             images[i] = imagedirectoryhigh[j] + "/" + imagebasename + twodigits(i) + imageextension;         }         (var = 1 ; < imagenumber+1 ; i++) {             $("#image" + j + "_" + i).attr("src",images[i]);         }     } } 

so question how can monitor downloads of images on client side : 4 out of 60 images loaded please wait...

i have checked : is there way determine when 4 images have been loaded using js? src written in html.

solution, aaron digulla, simple adding following event listener before assigning value src:

    $(imagesdom[i]).load(function () {             console.log("loaded");         }     ); 

thanks reading.

before assigning value src, attach event listener image. you'll need 2 global variables contain total image count , number of images have been loaded.

the question is there way determine when 4 images have been loaded using js? contains several examples how event listener looks like.

[edit] op used

$(imagesdom[i]).load(function () {console.log("loaded")}); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -