Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setTimeout help pls

Status
Not open for further replies.

g00fy

Programmer
Feb 16, 2003
2
AU
hi to all,

js is not my native language :)

can someone help with the logic on the previous function pls
i think code explains itself, else let me know.

thanx all

Code:
<html>
<head>
<title>Test Slideshow</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script>
var activeTimeout=false; 
var halt = false;
var backward = false;

var delay = 3000;  // image delay (millisec)
var transition = 0; // transition time (sec)

var imgObjects = new Array(&quot;about.gif&quot;, &quot;album.gif&quot;, &quot;about_over.gif&quot;) ;
var imageArray = new Array();

var a = 0;
var b;

for (i = 0; i < imgObjects.length; i++){
   imageArray[i] = new Image();
   imageArray[i].src = imgObjects[i];
}

function swapImage(){      
   b = document.images.SlideShow.src;
   if(!halt){	   
	   if (document.all){
		  document.images.SlideShow.style.filter=&quot;blendTrans(duration=2)&quot;;
		  document.images.SlideShow.style.filter=&quot;blendTrans(duration=transition)&quot;;
		  document.images.SlideShow.filters.blendTrans.Apply()      ;
	   }
	   if(!backward){
		   document.images.SlideShow.src = imageArray[a].src;   
		   if (document.all){
			  document.images.SlideShow.filters.blendTrans.Play();
		   }
		   a = a + 1;
	   }else{
	       document.images.SlideShow.src = b;   
		   if (document.all){
			  document.images.SlideShow.filters.blendTrans.Play();
		   }
		   backward = false;
	   }
	   if (a > (imgObjects.length-1)) 
		 a = 0;
	   activeTimeout = setTimeout(&quot;swapImage();activeTimeout=false&quot;, delay);
	}
}

function next(){
    halt = false;
	if (activeTimeout)
      clearTimeout(activeTimeout);
    swapImage();
   
}

function previous(){
   halt = false;
   if (activeTimeout)
      clearTimeout(activeTimeout);
   backward = true;
   swapImage();  
  
}

function stopNow(){
  halt = true;
  document.images.SlideShow.src = document.images.SlideShow.src;
  activeTimeout = false;
}

</script>



</head>

<body onload=&quot;swapImage()&quot;>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
    <td id=&quot;VU&quot; height=150 width=150> <img src=&quot;about.gif&quot; name='SlideShow' width=150 height=20></td>
</tr>
</table>  
<input type=&quot;submit&quot; name=&quot;prev&quot; value=&quot;<< Previous&quot; onClick=&quot;previous()&quot;>
<input type=&quot;submit&quot; name=&quot;stop&quot; value=&quot;Stop !&quot; onClick=&quot;stopNow()&quot;>
<input type=&quot;submit&quot; name=&quot;next&quot; value=&quot;Next >>&quot; onClick=&quot;next()&quot;>
</body>
</html>

gave you whole html so u can cut and paste if need be


kind regards,

g00fy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top