Using the method below to preload images, I have a simple question:

The same variable (in this case 'img') is being used for all preloaded
images.
Img.src is used to tell the browser to make a call to the server to fetch
the image

What if the connection to the server is slow (or the image is large) - does
the script wait until the image is loaded before continuing or is there a
chance that the variable will be overwritten (because of the loop) and its
source set to the next image before the first image is fully downloaded?

I use this script and it works fine, but I would like to find out if a
potentially slow client might have different results.

Thanks.


Sam Collett wrote:
> 
> Perhaps you could use something like this:
> 
> $.preloadImages = function()
> {
>       for(var i = 0; i<arguments.length; i++)
>       {
>               img = new Image();
>               img.src = arguments[i];
>       }
> }
> 
> Then you call it as soon as possible (it doesn't have to be in
> $(document).ready):
> 
> $.preloadImages("foo.gif", "bar.gif");
> $(document).ready(function() { ... });
> 
> On 28/09/06, Aljosa Mohorovic <[EMAIL PROTECTED]> wrote:
>> is there a preferred way to preload images when site uses jquery? how
>> do you usually preload images?
>>
>> Aljosa Mohorovic
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/image-preloading-tf2351203.html#a8805460
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to