preload an array of images with jquery

前端 未结 1 925
无人及你
无人及你 2021-01-13 03:10

I am using jQuery to build an array of images from a php array. I want to loop through these images, preloading them while displaying a little loading gif until all of the i

相关标签:
1条回答
  • 2021-01-13 03:56

    You are creating a sting and inserting it into the document, where it should become a part of DOM. What you need to do is create a JS Image object, somewhat like this:

    // Preload Images:
    for(i=0; i<imgCount; i++) { 
      var image_preload = new Image();
      image_preload.src = imgDir+imgArray[i];
    }
    
    0 讨论(0)
提交回复
热议问题