Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is it possible to preload images?

1 view
Skip to first unread message

Jeroen Koops

unread,
Dec 7, 1996, 3:00:00 AM12/7/96
to

Hi,

I'm kind of new to this Javascript-thing, so forgive me if
I should have looked somewhere else. And now the
question: I'm trying to do some animation using javascript
in Netscape 3.0, and I would like to fetch the images from
the server before the animation starts. Is there a method like
preload(image) I could use to accomplish this?

Please send any answers by email,
thanks in advance,

Jeroen Koops
jer...@nl.euro.net

Anthony K. Chu

unread,
Dec 7, 1996, 3:00:00 AM12/7/96
to

Yes. You can see how to do it at
http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/index.html
Go to the section on the Image object.

There also an example of this on my page.


Anthony K. Chu


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Second Year Computer Science Major http://www.webhaven.com/anthony/
University of British Columbia, Canada <anth...@unixg.ubc.ca>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ben Johnson

unread,
Dec 7, 1996, 3:00:00 AM12/7/96
to

I would guess that you could load them in as little tiny dots - using the
IMG tags of WIDTH=1 and HEIGHT=1 ,- They would stay in the browser's
cashe and would be instantly available for your real code. Unless the
cash has been turned off.....


<SIDENOTE>
Ug.... I had to find all the little bits of junk, IE threw all over my
hard drie. Would you beleive that it set constants in my autoexec.bat .
Sombody take that computer away from Bevis!

<SUCKS>
IE
</SUCKS>
</SIDENOTE>

---
Ben Johnson's Classic Video Games
One Convenient Location:
http://www.halcyon.com/benj/

Cam Chalmers

unread,
Dec 10, 1996, 3:00:00 AM12/10/96
to

To preload I use

n = numberofImages;
ImgArray = new Array(n);
for (i=0;i>n;i++){
ImgArray[n] = New Image();
}

ImgArray[0].src = "whatnot.gif";
ImgArray[1].src = "your.gif";

--Cam
PS, is it my news server, or has this news group only gotten 8 messages
in the last 4 days?

Kevin Van Sant

unread,
Dec 11, 1996, 3:00:00 AM12/11/96
to

On Tue, 10 Dec 1996 08:09:31 -0500, Cam Chalmers
<ccha...@atldev.com> wrote:

>PS, is it my news server, or has this news group only gotten 8 messages
>in the last 4 days?

It is your server, I'm getting about , oh maybe 50 or so a day.
A reliable newsfeed seems to be the hardest thing for most ISPs to
provide.

Gavin Lambert

unread,
Dec 15, 1996, 3:00:00 AM12/15/96
to

In article <32AD61...@atldev.com>, ccha...@atldev.com says...

>
>To preload I use
>
>n = numberofImages;
>ImgArray = new Array(n);
>for (i=0;i>n;i++){
> ImgArray[n] = New Image();
>}
>
>ImgArray[0].src = "whatnot.gif";
>ImgArray[1].src = "your.gif";

Ummm.. I hope you don't.....

I think what you meant was:

for (i=0;i<n;i++) {

... just a slight bug.

BTW, there is no point calling 'new Array(n)'. JavaScript has dynamic property
allocation. It's quite happy with plain old 'new Array()'.

Another approach is to do something a bit nasty, but it works:

function Preload(prel,url,width,height) {
if(width && height)
prel = new Image(width,height);
else
prel = new Image();
prel.src = url;
}

then calling like:

imgs = new Array();
Preload(imgs[0],"one.gif");
Preload(imgs[1],"two.gif",50,70);
Preload(imgs[2],"title.gif",100,60);

etc, etc.

-----
Gavin Lambert
uec...@geocities.com
http://www.geocities.com/SiliconValley/Heights/1987


0 new messages