Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Preload Images. Please, help me out. Thank You.

Reply
Thread Tools

Preload Images. Please, help me out. Thank You.

 
 
shapper
Guest
Posts: n/a
 
      11-25-2006
Hello,

I think to preload an image I should us something like:

img = new Image();
img.src = 'images/img.jpg';

Could someone tell me how to create a loop which would preload a list
of images?
Something like:

ImagesFolder = '...';
ImagesNames = '...';

For i = 0 to ImagesNames.Count
img = new Image();
img.src = imagesFolder + imagesNames(i)
End

Is this a good approach?
Could someone tell me the javascript code for this?
I am not very confortable with javascript.

Thank You,
Miguel

 
Reply With Quote
 
 
 
 
Jonas Raoni
Guest
Posts: n/a
 
      11-25-2006
shapper escreveu:
> Is this a good approach?
> Could someone tell me the javascript code for this?
> I am not very confortable with javascript.


Take a look if this helps: <URL:http://jsfromhell.com/classes/preloader>


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
 
Reply With Quote
 
 
 
 
mick white
Guest
Posts: n/a
 
      11-25-2006
shapper wrote:
> Hello,
>
> I think to preload an image I should us something like:
>
> img = new Image();
> img.src = 'images/img.jpg';
>
> Could someone tell me how to create a loop which would preload a list
> of images?
> Something like:
>
> ImagesFolder = '...';
> ImagesNames = '...';
>
> For i = 0 to ImagesNames.Count
> img = new Image();
> img.src = imagesFolder + imagesNames(i)
> End


imgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];
for(var i=0;i<imgs.length;i++){
pic[i]=new Image()
pic[i].src=imgs[i];
}

Something like that
Mick
>
> Is this a good approach?
> Could someone tell me the javascript code for this?
> I am not very confortable with javascript.
>
> Thank You,
> Miguel
>

 
Reply With Quote
 
webEater
Guest
Posts: n/a
 
      11-25-2006


On 25 Nov., 18:31, mick white <m...@mickweb.com> wrote:
> shapper wrote:
> > Hello,

>
> > I think to preload an image I should us something like:

>
> > img = new Image();
> > img.src = 'images/img.jpg';

>
> > Could someone tell me how to create a loop which would preload a list
> > of images?
> > Something like:

>
> > ImagesFolder = '...';
> > ImagesNames = '...';

>
> > For i = 0 to ImagesNames.Count
> > img = new Image();
> > img.src = imagesFolder + imagesNames(i)
> > Endimgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];

> for(var i=0;i<imgs.length;i++){
> pic[i]=new Image()
> pic[i].src=imgs[i];
>
> }Something like that
> Mick
>
>
>
> > Is this a good approach?
> > Could someone tell me the javascript code for this?
> > I am not very confortable with javascript.

>
> > Thank You,
> > Miguel


Better create REAL images, means document.body.appendChild them to your
site and simply set display="none" or visibility="hidden", so they are
really preloaded. My experience with new Image() ... is bad, not all
browser preload them onload. Example

imgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];
for(var i=0;i<imgs.length;i++){
// why make an image array, excepting you want get the images
explicitly. Important is, that the browser loads the image data.
var im = document.createElement('img'); // probably the same as new
Image(), I dont know.
im.src=imgs[i];
im.style.width = im.style.height = '0';
im.style.visibility = 'hidden';
// I am not sure if your browser loads them using display="none"
}

Andi

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      11-26-2006
shapper a écrit :
> I think to preload an image I should us something like:
>
> img = new Image();
> img.src = 'images/img.jpg';
>
> Could someone tell me how to create a loop which would preload a list
> of images?
> Something like:
>
> ImagesFolder = '...';
> ImagesNames = '...';
>
> For i = 0 to ImagesNames.Count
> img = new Image();
> img.src = imagesFolder + imagesNames(i)
> End


imgs=["a.gif","../b.gif","http://example.com/imgs/c.gif" ...],pics=[];

function postLoad(k, max){
if(k<max) {
pic[k] = new Image();
pic[k].onload = function(){postLoad(k,max)};
pic[k].src = imgs[i];
k++;
}
}

onload = function(){ postLoad(0, imgs.length); };


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact : http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
upgrade preload software and now no wireless!!!!! =?Utf-8?B?ZXJvY2ttYW4=?= Wireless Networking 1 04-03-2005 12:54 PM
Preload Firefox Plugin Gary Walker Firefox 0 01-06-2005 04:20 AM
Preload Audio? - Novice Needs Help OysterCracker Javascript 2 02-19-2004 01:25 AM
Thank You CJ, Thank Mike! mytho Computer Support 7 11-23-2003 06:50 AM
Thank You CJ, Thank Mike! mytho Computer Support 0 11-22-2003 01:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57