Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:08:35+00:00 2026-06-01T10:08:35+00:00

I put together an image preloader which works fine, but what doesn’t work is

  • 0

I put together an image preloader which works fine, but what doesn’t work is updating the status after every image that has been loaded. Instead, all images are loaded and “done” (last line) is the only thing that shows up. It does work when I use an alert instead of the innerHTML command, but that is obviously of no use. What am I doing wrong?

<div id="preloader">
<span id="preloader_status"> </span>
<script language="JavaScript">
    imageObj = new Image();
    images = new Array();
    images[0]="bigimage.gif"
    images[1]="anotherbigimage.gif"
    /* and so on */

    var i = 0;
    var o = (images.length);

    for (i=0;i<o;i++) {
        var status = (Math.round(100*(i/o)));
        imageObj.src=images[i];
        document.getElementById("preloader_status").innerHTML = status;
    }
    document.getElementById("preloader_status").innerHTML = "done";
 </script>
 </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:08:37+00:00Added an answer on June 1, 2026 at 10:08 am

    To show image load progress, you will need to hook into the onload event for the images so you can track when their loading is actually complete. Images are loaded asychronously so assigning .src only STARTS the loading of the image. It is not completed until later when the onload handler is called. Because of that, your existing code will just immediately show “done” because it isn’t tracking when the images are actually done loading.

    In addition, you were successively assigning a new .src value to the same image object which is going to abort the previous image loading. You need to create a new image object for each new image you are loading.

    You can fix your code like this:

    <div id="preloader">
    <span id="preloader_status"> </span>
    <script language="JavaScript">
        var imageSrcs = [
            "bigimage.gif",
            "anotherbigimage.gif"
            /* and so on */
        ];
    
        function preloadImages(list, statusID) {
            var img, cnt = 0;
            var progress = document.getElementById(statusID);
            var preloads = [];
    
            for (var i = 0; i < list.length; i++) {
                img = new Image();
                img.onload = function() {
                    ++cnt;
                    var loadPercent = Math.round(100*(cnt/list.length));
                    progress.innerHTML = loadPercent;
                    if (cnt == list.length) {
                        progress.innerHTML = "done";
                    }
                }
                img.src = list[i];
                preloads.push(img);
            }
        }
    
        preloadImages(imageSrcs, "preloader_status");
     </script>
     </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I put together the following method, which calls my repository to get an image
Put together an extremely simple Knockout.js exmaple to learn how it works. I immediately
I'm trying to put together a Java Webstart app, but don't want it to
I hope someone can help us. We’re trying to put together an image editor,
I put together a quick WinForm/embedded IE browser control which logs into our company's
I've been trying to put together a script which allows a user to select,
I have a requirement to put together an application which will generate a web
I have put together a script which is very much like the flickr photostream
How can I put together on the same view, an image and text? I
I've put together a PHP script and small form which allows the user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.