|
Q754 How can I create a functions that cycle foward and backward through an array of images?
irt.org | Knowledge Base | JavaScript | Image | Q754 [ previous next ]
Q754 How can I create a functions that cycle foward and backward through an array of images?
It depends what you mean by an array of images. If you mean something
like:
<SCRIPT LANGUAGE="JavaScript"><!--
var arrayOfImages = new Object();
var index = 0;
arrayOfImages[index++] = 'picture1.gif';
arrayOfImages[index++] = 'picture2.gif';
arrayOfImages[index++] = 'picture3.gif';
arrayOfImages[index++] = 'picture4.gif';
arrayOfImages[index++] = 'picture5.gif';
//--></SCRIPT>
|
Then you can use:
<SCRIPT LANGUAGE="JavaScript"><!--
var start = 0;
function next() {
if (document.images) {
start++;
if (start > index)
start = index;
else
document.images['imageName'].src = arrayOfImages[start];
}
}
function last() {
if (document.images) {
start--;
if (start < 0)
start = index;
else
document.images['imageName'].src = arrayOfImages[start];
}
}
//--></SCRIPT>
|
Feedback on 'Q754 How can I create a functions that cycle foward and backward through an array of images?'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.