Sometimes, we need to rotate images on ours web pages, it may be ads or some simple images.Below you'll find the code for implementing the same.
You can create as many image rotations you want, you just need to specify the urls of the images in an Array, and the object where the image will be shown. The function RotateImages is called with the Array/Img Object number, and at what index of the array the rotation should start.
Few more Interesting JavaScript Scripts
Auto Suggest with Javascript
Hide/Show and Toggle DIV usng JavaScript
Arrays in Java script
Sorting A Un-Ordered List (UL) Using JavaScript
Timer In JavaScript
You can create as many image rotations you want, you just need to specify the urls of the images in an Array, and the object where the image will be shown. The function RotateImages is called with the Array/Img Object number, and at what index of the array the rotation should start.
HTML Code:
<html> <head> <title>Image Rotate </head> <body> <img src="" name="Rotating" id="Rotating1" width=100 height=100> <img src="" name="Rotating" id="Rotating2" width=100 height=100> <script language="JavaScript"> var ImageArr1 = new Array("Picture(3).jpg","Picture(1).jpg","Picture(2).jpg"); var ImageHolder1 = document.getElementById('Rotating1'); var ImageArr2 = new Array("Picture(5).jpg","Picture(6).jpg","Picture(7).jpg"); var ImageHolder2 = document.getElementById('Rotating2'); function RotateImages(whichHolder,Start) { var a = eval("ImageArr"+whichHolder); var b = eval("ImageHolder"+whichHolder); if(Start>=a.length) Start=0; b.src = a[Start]; window.setTimeout("RotateImages("+whichHolder+","+(Start+1)+")",1500); } RotateImages(1,0); RotateImages(2,0); </script> </body> </html>
Auto Suggest with Javascript
Hide/Show and Toggle DIV usng JavaScript
Arrays in Java script
Sorting A Un-Ordered List (UL) Using JavaScript
Timer In JavaScript

