List Info

Thread: Random Image Display Question




Random Image Display Question
country flaguser name
United States
2007-02-13 11:30:26
I am using setTimeout( ) to continuously call a function
that randomly
rotates/displays 2 images on a page. The part I need help
with is the
second image should rotate 3 seconds after the first image
rotates. I
cannot figure out how to accomplish the 3 second delay. My
code is
pasted below:

function randPic(){
   randPic1();
   randPic2();

}

function randPic1(){
   picIndex = picIndex + 1;
      if (picIndex>=middlepics.length)
         picIndex = 0;
     
d.images["pic1"].src="images/middle/"+mi
ddlepics[picIndex];
      d.images["pic1"].alt=middlealts[picIndex];

	  timerID=setTimeout("randPic1()",3700);
}

function randPic2(){
   bottomPicIndex = bottomPicIndex + 1;
	  if (bottomPicIndex>=bottompics.length)
         bottomPicIndex = 0;
      d.images["pic2"].src="images/
bottom/"+bottompics[bottomPicIndex];
     
d.images["pic2"].alt=bottomalts[bottomPicIndex];

	 timerID=setTimeout("randPic2()",5500);
}

The randPic( ) function is called in the onLoad event of the
body tag.
Any ideas you may have would be greatly appreciated.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Random Image Display Question
country flaguser name
United States
2007-02-27 07:37:27
You could use setInterval() instead, that way your function
would be
executed in an interval, rather than after a timeout. To
make the
second picture rotate after the first one, I'd call the
randPic2()
from within the first picture and with a timeout. that way
your first
picture controls your second picture.

On Feb 13, 6:30 pm, "Newbie" <nikki_herr...comcast.net> wrote:
> I am using setTimeout( ) to continuously call a
function that randomly
> rotates/displays 2 images on a page. The part I need
help with is the
> second image should rotate 3 seconds after the first
image rotates. I
> cannot figure out how to accomplish the 3 second delay.
My code is
> pasted below:
>
> function randPic(){
>    randPic1();
>    randPic2();
>
> }
>
> function randPic1(){
>    picIndex = picIndex + 1;
>       if (picIndex>=middlepics.length)
>          picIndex = 0;
>      
d.images["pic1"].src="images/middle/"+mi
ddlepics[picIndex];
>      
d.images["pic1"].alt=middlealts[picIndex];
>
>          
timerID=setTimeout("randPic1()",3700);
>
> }
>
> function randPic2(){
>    bottomPicIndex = bottomPicIndex + 1;
>           if (bottomPicIndex>=bottompics.length)
>          bottomPicIndex = 0;
>       d.images["pic2"].src="images/
> bottom/"+bottompics[bottomPicIndex];
>      
d.images["pic2"].alt=bottomalts[bottomPicIndex];
>
>         
timerID=setTimeout("randPic2()",5500);
>
> }
>
> The randPic( ) function is called in the onLoad event
of the body tag.
> Any ideas you may have would be greatly appreciated.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )