[Ilugc] Javascript for slideshow

  • From: gopal@xxxxxxxxxxxxxxxxx (Gopalarathnam Venkatesan)
  • Date: Sun Oct 8 22:58:36 2006

Girish Venkatachalam wrote:

Dear Javascript hackers,

     I wanted to make a slideshow and I got this script from google. But I 
find it somewhat ugly. Can someone give me a better alternative and also 
explain what is going on? Thanks a million. 

regards,
Girish

<SCRIPT LANGUAGE="JavaScript">
     <!--

     //set image paths
     src = ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", 
"image5.jpg", "image6.jpg"]


     //set duration for each image
     duration = 4;


     ads=[]; ct=0;
     function switchAd() {
           var n=(ct+1)%src.length;
           if (ads[n] && (ads[n].complete || ads[n].complete==null)) {
                   document["Ad_Image"].src = ads[ct=n].src;
           }
           ads[n=(ct+1)%src.length] = new Image;
           ads[n].src = src[n];
           setTimeout("switchAd()",duration*1000);
     }
function doLink(){
      location.href = url[ct];
} onload = function(){
      if (document.images)
              switchAd();
}
//-->
</SCRIPT>

<A HREF="javascript:doLink();" onMouseOver="status=url[ct];return true;" 
onMouseOut="status=''">
 <IMG NAME="Ad_Image" SRC="image1.jpg" BORDER=0>
 </A>


Ah, I see lots of global variables, and poorly written code.

Fine, I've managed to quickly whip a trivial implementation of a slide 
show manager in 15mins, mail me if you have any questions.

I believe my code is self explanatory ;-)

-- 
Gopalarathnam Venkatesan

http://gopalarathnam.com/
-------------- next part --------------

Other related posts: