BetaONE will rise again!

BetaONE will rise again! (http:\\b1.hcanet.com\forum/index.php)
-   Web Development (http:\\b1.hcanet.com\forum/forumdisplay.php?f=50)
-   -   Validate If An Image Fully Preloaded? (http:\\b1.hcanet.com\forum/showthread.php?t=10198)

SlickVic78 20th Dec 03 08:52 PM

I wanted to know if there was a way to validate if an image fully preloads before it goes on to the next step within the code... I tried putting in a flag but I don't think it is working...

Preload Function:
Code:

var preloaded = false;
function preload() {
      if (!document.images) return;
      var ar = new Array();
      var arguments = preload.arguments;
 &nbsp; &nbsp; &nbsp;for (var i = 0; i < arguments.length; i++) {
        ar[i] = new Image();
        ar[i].src = arguments[i];
 &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp;preloaded = true;
}

Check Preloaded
Code:

function checkpreload(){
 &nbsp; &nbsp; &nbsp;if (preloaded){
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;changeImage();
 &nbsp; &nbsp; &nbsp;} else {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newImage = "url(images/gfx_photos/loading_image.gif)";
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.getElementById('loading').style.backgroundImage = newImage;
 &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp;setTimeOut(checkpreload(),1000);
}

In the body tag, I have onLoad="preload('imagetoload.jpg');checkpreload(); "

+ So this is what I am wanting this code to do, start to preload an image by calling the preload() function.

+ Next call up the checkpreload() function to see if the image has finished preloading. If so, display the image by calling the changeImage() function. If not fully preloaded, then display a loading image graphic.

+ Every 1 second, call the checkpreload() function to see if the image has preloaded.

The problem, I think, is that the preloaded value is being set to "true" too soon without the image fully preloading...

Is there a way I can validate that the image has preloaded before passing a "true" value to the preloaded variable?

Why am I doing this? Well, for people who have dialup... I want to be able to display the message that an image is loading and then as soon as the image preloads, display it... What happens right now, is that you may get the image loading graphic for a second, then it disappears, you then have to wait an additional 20 seconds before the image actually appears.

Any help would be great!

Thanks!
-SlickVic78

SlickVic78 20th Dec 03 11:11 PM

Figured it out... I ended up finding a sample source and worked with it to accomplish what I wanted.

Will an Admin or Mod please close this thread.

Thank you,
-SlickVic78

DoG 20th Dec 03 11:58 PM

Closed as requested :)


All times are GMT +1. The time now is 07:22 PM.

Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.