View Full Version : setInterval() for loop
scriptkeeper
05-28-2003, 05:26 AM
Is there a way to put a delay on a loop counter with setInterval() or something. I tried to use the break and continue to continue to add delay at end. But it didn't work any ideas?
Slurry
05-28-2003, 07:17 AM
try using a function and setTimeout e.g.:
var flag=0
var delay=1000
function yourFunction() {
if (flag < 10) {
// Do stuff here
setTimeout('yourFuntion()', delay);
}
flag++;
}
Is this what you has in mind?
A1ien51
05-28-2003, 07:23 AM
you can clear the interval and restart it.....
scriptkeeper
05-28-2003, 03:45 PM
well I wrote a function just like that to simply switch throught the pix in my slideshow. But it won't work, I dont understand I have seen this done before?
A1ien51
05-28-2003, 07:10 PM
Here is the basic idea of the slideshow
<script>
currentpic=0;
NumPics=5;
PauseTime=1000;
function SlideIt(){
document.FormName.PicName.src="PIC"+currentpic +".gif"
currentpic++;
if(currentpic>=5)currentpic=0;
ABC=setTimeout("SlideIt()",PauseTime);
}
</script>
if your pics are named differently, then you can use an array to flip through the pictures. On dynamci drive and JavaScriptKit there are slew of these types of scripts.
A1ien51
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.