Javascript to rotate images in a website

NOTE:   this is a light weight, easy way to have rotating images or pictures in a website without using more complicated tools like Flash.

Step 1 - Edit the html behind your image to have an ID setting equal to "rotating1" as shown here:

<img src="images/iaswing.jpg" id= "Rotating1" width="900" height="320" />

Step 2 - paste this code into your hmtl

<script language="JavaScript">
   function RotateImages(Start)
  {
      var a = new Array("images/image1.jpg","images/image2.jpg","images/image3.jpg");
      var b = document.getElementById('Rotating1');
      if(Start>=a.length)
          Start=0;
      b.src = a[Start];
      window.setTimeout("RotateImages(" + (Start+1) + ")",4000);
  }
  RotateImages(0);
  </script>

Step 3 - edit how quickly the images rotate by changing the 4000 above to whatever value you want

Comments