Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > loop through an array and load image

Thread Tools

loop through an array and load image
Posts: n/a
Here is some idea of what I am trying to do.

1 - Preload my images to the page.
2 - When user clicks the imgclick.gif
2 - the javascript will loop through these images one at a time at
approximatly 50 millisconds using id="imgmain" as its holder.
3 - when the javascript gets to the the last image in the loop I need
to have another webpage load with the target being _self.

Here is the javascript that I have so far.



<script language="javascript"><!--
//Preload Images
var image01 = new Image();
image01.src = "images/img1.gif";
var image02 = new Image();
image02.src = "images/img2.gif";
var image03 = new Image();
image03.src = "images/img3.gif";

function doPreload()
var the_images = new Array('images/img1.gif',
function preloadImages(the_images_array) {
for(var loop = 0; loop < the_images_array.length;
var an_image = new Image();
an_image.src = the_images_array[loop];

// Not sure how to build a function here that will loop through the
images(or the Array) and and load the images into the "imgmain".


<meta content="Microsoft Visual Studio .NET 7.1"
<meta content=""

<body onload="doPreload();">
<IMG id="imgmain" src="images/img1.gif" border="0">
<IMG id="imgclick" src="images/imgclick.gif">


Any help would be greatly appreciated.

Reply With Quote

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
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
If-Else within a loop going through array elements... Saeed Bhuta Ruby 5 04-22-2010 01:40 PM
help with design - reload image on image load; avoid infinite loop lawpoop Javascript 17 06-22-2009 06:59 PM
Re: How to loop through a list while inside the loop, the list size may be decreased? Roedy Green Java 3 09-13-2008 01:51 AM
Dynamically loop through array of structures uidzer0 C Programming 3 04-28-2008 03:36 AM