Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto change a picture in web page

Status
Not open for further replies.

MasterofNone

Technical User
Jun 30, 2002
136
GB
I am looking to create an internal web page which has a single image file. That is the easy part. As someone who has never really touched frontpage or tried to create web pages before I might be over reaching myself. What I would like to do is have the image file change every few minutes for a predefined number of images.

Is this possible and can anybody point me in the right direction.

Thanks
 
Probably the easiest way is to use a pre-written javascript for this. I have successfully used this one:
If you have any questions about this, I suggest you ask them in forum216

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Have a look at the setInterval function. You could write a simple javascript function to change the image, and call setInterval to run the function every so often:

Code:
/* the list of images we're using */
var arrImages = new Array() ;
arrImages[0] = new Image(image url) ;
arrImages[1] = new Image(image url) ;
arrImages[2] = new Image(image url) ;

/* the current image */
var currImage = 0 ;

/* how many minutes before image swaps */
var intMinutes = 3 ;

/* the image placeholder */
var imgPlace = document.getElementById("imgPlaceholder") ;

function swapImage() {
  // make sure we don't blow past array bounds
  if (currImage == 2) currImage = 0 ;

  imgPlace.src = arrImages[currImage] ;
}

var timer = setInterval("swapImage()", intInterval*60000) ;

or something like that anyways ...

HTH



Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top