Forum Moderators: open
-- in header
var interval = 2.5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;
var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("http://mysite.com/img/01.jpg");
image_list[image_index++] = new imageItem("http://mysite.com/img/02.jpg");
image_list[image_index++] = new imageItem("http://mysite.com/img/03.jpg");
image_list[image_index++] = new imageItem("http://mysite.com/img/04.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "rotateImage('"+place+"')";
setTimeout(recur_call, interval);
}
-- Body tag
<BODY OnLoad="rotateImage('MyImage')">
-- In body
<center>
<img name="MyImage" src="http://mysite.com/img/01.jpg" width=120 height=90> <!-- Change width and height to match your image size. I would size all your images the same-->
</center>
I implemented this script no problem, and am happy with the results. I have a photo of a lighthouse that rotates between the regular photo, and the second photo has the light "photoshopped" on. This is rotated for 2 seconds... 2 seconds on, and then 2 seconds off.
Is there any way to change the length of time that one of the images shows? IE, to make one picture show for 3 seconds, and the other for 1 second?
kbmcdowell
intervals=new Array();
intervals[0]=2.5;
intervals[1]=1.5;
intervals[2]=4;
intervals[3]=1;// delay between rotating images (in seconds). Make sure there are as many of these entries as there are of images.
var random_display = 1; // 0 = no, 1 = yes
var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("http://mysite.com/img/01.jpg");
image_list[image_index++] = new imageItem("http://mysite.com/img/02.jpg");
image_list[image_index++] = new imageItem("http://mysite.com/img/03.jpg");
image_list[image_index++] = new imageItem("http://mysite.com/img/04.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
timesdone=-1;
maxtimes=image_list.length;function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "rotateImage('"+place+"')";
if(timesdone==maxtimes)
{
timesdone=0;
}
else
{
timesdone++;
}setTimeout(recur_call, intervals[timesdone]);
}
[simplythebest.net...]
Plus there are tons of other ones too. The banner up one I modified so handle several images rotating in and out with links to different places for each image, so its pretty versatile and not overwhelming tough to figure out.
maxtimes=image_list.length-1;
Your variable caused all values in the array to display, plus one additional image again. So my images were displaying like this:
0,1,2,3,4,5,0
1,2,3,4,5,0,1
2,3,4,5,0,1,2
Apparently I can not post an outside link to show the resulting success, so I will not do so. Thanks again.