Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setTimeout help pls

    sorry subject should say setTimeout help pls

    hi to all,

    can u pls look at code below and tell me why my previous method is not happening properly.

    i think code explains itself, else let me know.

    the timeout is not resetting on previous function


    thanx all

    Code:
    <html>
    <head>
    <title>Test Slideshow</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <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("about.gif", "album.gif", "about_over.gif") ;
    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="blendTrans(duration=2)";
    		  document.images.SlideShow.style.filter="blendTrans(duration=transition)";
    		  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("swapImage();activeTimeout=false", 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="swapImage()">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td id="VU" height=150 width=150> <img src="about.gif" name='SlideShow' width=150 height=20></td>
    </tr>
    </table>  
    <input type="submit" name="prev" value="<< Previous" onClick="previous()">
    <input type="submit" name="stop" value="Stop !" onClick="stopNow()">
    <input type="submit" name="next" value="Next >>" onClick="next()">
    </body>
    </html>
    gave you whole html so u can cut and paste if need be


    kind regards,

    g00fy
    Last edited by g00fy; 02-23-2003 at 08:24 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •