How to change the interval in a setInterval as it is running?

S

Simon Wigzell

I have a slide show that uses setInterval to move through the iamges. I
would like to offer the visitor the option of changing the speed as it is
running. I see an example of this here
http://www.sidney.ca/dynamic/Page1251.aspx?PageMode=Hybrid but cannot find
the source for it.

I could have it in a form and refresh the page but I would rather do it
dynamically like this example. Any ideas?
 
D

Dr J R Stockton

Sun said:
I have a slide show that uses setInterval to move through the iamges. I
would like to offer the visitor the option of changing the speed as it is
running. I see an example of this here
http://www.sidney.ca/dynamic/Page1251.aspx?PageMode=Hybrid but cannot find
the source for it.

I could have it in a form and refresh the page but I would rather do it
dynamically like this example. Any ideas?

Clear the timeout without displaying, and start another.

Or use setTimeout or setInterval set to (say) one second as a "wake-up",
and, at each arousal, consult a rate control to see if enough time has
elapsed.

If you can afford to change the rate only after the current wait, just
read the new timeout from a control each time.


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
T

Thomas 'PointedEars' Lahn

Simon said:
I have a slide show that uses setInterval to move through the iamges. I
would like to offer the visitor the option of changing the speed as it is
running.

A) var timeout = window.setTimeout(..., x);
...
window.clearTimeout(timeout);
timeout = window.setTimeout(..., y);

B) var intv = window.setInterval(..., x);
...
window.clearInterval(intv);
intv = window.setInterval(..., y)

Approach B has the advantage of creating a new item only the first time
and when the speed should change; it has the disadvantage of being slightly
less supported and AIUI has a lesser chance of being executed real-time.

I see an example of this here

View Page Source, search for `<script' or, in this case, `javascript:'.

It might also help to http://getfirebug.com/


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,157
Messages
2,570,879
Members
47,413
Latest member
KeiraLight

Latest Threads

Top