Jump to content

Start/Stop Timing HELP!


phpadam

Recommended Posts

Here's my full code, but this question is mostly concerning function cycle()

<div id="slideshow">
<div id="main">
<div id="placehold">
</div>
<div id="caption">
</div>
</div>
<div id="roll">
<center>
<img src="1.jpg" id="1" alt="Caption1" style="width:90px;height:60px;opacity:0.5;filter:alpha(opacity=50)"  onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.5;this.filters.alpha.opacity=50" onclick="document.getElementById('main').style.backgroundImage='url(1.jpg)'" />
<img src="2.jpg" id="2" alt="Caption2" style="width:90px;height:60px;opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.5;this.filters.alpha.opacity=50" onclick="document.getElementById('main').style.backgroundImage='url(2.jpg)'" />
<img src="3.jpg" id="3" alt="Caption3" style="width:90px;height:60px;opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.5;this.filters.alpha.opacity=50" onclick="document.getElementById('main').style.backgroundImage='url(3.jpg)'" />
<img src="4.jpg" id="4" alt="Caption4" style="width:90px;height:60px;opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.5;this.filters.alpha.opacity=50" onclick="document.getElementById('main').style.backgroundImage='url(4.jpg)'" />
<img src="5.jpg" id="5" alt="Caption5" style="width:90px;height:60px;opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.5;this.filters.alpha.opacity=50" onclick="document.getElementById('main').style.backgroundImage='url(5.jpg)'" />
<img src="6.jpg" id="6" alt="Caption6" style="width:90px;height:60px;opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.5;this.filters.alpha.opacity=50" onclick="document.getElementById('main').style.backgroundImage='url(6.jpg)'" />
</center>
</div>
</div>
<script type="text/javascript">
function cycle() {
var current = document.getElementById("main").style.backgroundImage;
if ( current == '' ) {
var numb = 1;
} 
if ( current == "url(6.jpg)" ) {
var numb = 1;
}
if ( current != '' && current != "url(6.jpg)" ) {
var numb = current.charAt(4);
var numb = parseInt(numb) + 1;
}
var numbstr = "url("+numb+".jpg)";
document.getElementById("main").style.backgroundImage=numbstr;
setTimeout("cycle()", 5000);
}
onload=function (){cycle()};
</script>

 

As you can see, the script cycles between changing the main picture every five seconds.  But when a user clicks on the thumb of that image, the main picture changed as well, yet the script doesn't stop it's rhythm of five seconds, so if a user clicks on a thumbnail at the end of a five second cycle, the picture won't stay up for long.  How would I go about resetting the timer to the beginning of five seconds every time a user selects a thumbnail? I realize I will probably have to get rid of setTimeout as it is, and maybe include a global time interval variable?

 

Help please, thanks in advance.

 

-Adam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.