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!

Timer to end execution of slideshow 1

Status
Not open for further replies.

GaryCam

Programmer
Dec 16, 2003
69
US
I know virtually nothing about JS. (In fact, I don't know why I'm classified as a Programmer on this forum). I've tried to find a solution to this for several hours before bothering you folks with what is certainly a very simple question.

I found a JS script for a slideshow. Once it starts (via onMouseover) it runs through an array of images over and over. That's great. What I need now is a way to stop its execution after a set length of time, say 5 seconds. Here's the script:

Code:
var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  if (document.all)
  {
    document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
    document.getElementById(pictureName).filters.blendTrans.Apply();
  }
  document.getElementById(pictureName).src = nextImage;
  if (document.all)
  {
    document.getElementById(pictureName).filters.blendTrans.Play();
  }
   var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
    + ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"',"+displaySecs+")",
    displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null) {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}

Thanks in advance,
Gary
 
You need to assign the result of the "setTimeout" call to a variable:

Code:
[!]var timerHandle = [/!]setTimeout("RunSlideShow('" + pictureName + "', '" + futureImages + "', " + displaySecs + ")", displaySecs * 1000);

And then you can use another timer to stop that one:

Code:
setTimeout('clearTimeout(timerHandle);', 5000);

Incidentally, it looks as if the code you've got is IE-only. Why not find a decent slideshow script that works cross-browser? There are many to choose from.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks, Dan. I will use your approach AND look for a cross-browser script.

Thanks again, Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top