[Techtalk] script
Almut Behrens
almut-behrens at gmx.net
Sat Apr 12 00:54:21 EST 2003
On Fri, Apr 11, 2003 at 11:56:41AM -0500, abbey wrote:
> On Fri April 11 2003 11:20 am, wolf wrote:
> > Having the same problem here : )
> > Just assumed it was me : )
>
> I am no javascript wizard by any means, but I didn't see where the photos were
> loaded into any kind of an array. I've adapted some scripts in the past and
> usually there's an array?
actually, the array there :)
...
imgs = new Array();
for (i=0; i<n; i++) {
// preload images, so they are in the cache
imgs[i] = new Image();
imgs[i].src = img_url[i];
}
...
However, you could also get along without any array at all, e.g.
<html>
<head>
<script language="JavaScript">
function showimg(url) {
document.myimg.src = url;
}
setTimeout('showimg("images/frame2.jpg")', 1000);
setTimeout('showimg("images/frame3.jpg")', 2000);
setTimeout('showimg("images/frame4.jpg")', 3000);
</script>
</head>
<body>
<img src="images/frame1.jpg" name="myimg");
</body>
</html>
This would display four images, one per second (it does not cycle
through them, though).
Also note, that the setTimeout() function only schedules the calling
of the functions showimg(), it does _not_ wait for them to execute.
Thus, you need different delay intervals 1000, 2000, 3000 to get a
slide show. With all delays being 1000, all images would be displayed
at the same time...
Almut
More information about the Techtalk
mailing list