[Javascript] Creating a DOM based Image Rotator

Triche Osborne wdlists at triche-osborne.com
Thu Aug 18 15:42:34 CDT 2005


Harvey A. Ramer wrote:
> The script does run on Firefox but requires me to use "name" rather than
> "id". This is invalid XHTML.
> 
> I would like to use the id attribute. I think it requires using
> getElementById and I'm not quite sure how to approach it. Probably simple.
> I'll get it when I have time if no one else has the immediate fix.
> 
I don't have your images so I couldn't test the rotation part, but 
(using id="rotateImg"), the following does identify the proper image for 
replacement:

var rotateImages = new 
Array("/images/rotate/1.jpg","/images/rotate/2.jpg","/images/rotate/3.jpg","/images/rotate/4.jpg","/images/rotate/5.jpg","/images/rotate/6.jpg","/images/rotate/7.jpg","/images/rotate/8.jpg");
var thisImage = 0;
var imageCt = rotateImages.length;
var curDocImg;

//On load, get placeholder image element.
window.onload = function()
{
	curDocImg = document.getElementById("rotateImg");
}

function rotate()
{
	if (curDocImg.complete)
	{
		thisImage++;

		if (thisImage == imageCt)
		{
			thisImage=0;
   		}

		curDocImg.src = rotateImages[thisImage];
		setTimeout("rotate()", 6*1000)
	}
}

Triche




More information about the Javascript mailing list