473,411 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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

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/Page125...ageMode=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?
Sep 2 '07 #1
3 20887
Simon Wigzell said the following on 9/2/2007 3:25 PM:
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/Page125...ageMode=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?

The script is in the page (part of it) and part of it is here:

http://www.sidney.ca/dynamic/cm/webu...s/slideshow.js

To answer your question, you use setTimeout with a variable and change
that variable.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 2 '07 #2
Simon Wigzell wrote:
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
http://www.sidney.ca/dynamic/Page125...ageMode=Hybrid but cannot find
the source for it.
View Page Source, search for `<script' or, in this case, `javascript:'.

It might also help to http://getfirebug.com/
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 2 '07 #3
In comp.lang.javascript message <u6ECi.116300$rX4.48684@pd7urf2no>, Sun,
2 Sep 2007 19:25:14, Simon Wigzell <si**********@shaw.caposted:
>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/Page125...ageMode=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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
2
by: Jim Red | last post by:
hello, how can i set an interval inside a class exmpl. var Class = (function() { var interval = undefined; function initInterval(instance) { interval = setInterval("doSomething", 1000,...
2
by: Andrew | last post by:
hi, how can i log (in the eventlog or in a file) the activity of my pc... i need to monitor at regular interval the running applications (like showed in task monitor...)on my machine, and if's...
8
by: Boni | last post by:
Dear all, imagine this is scroll bar. Min|-------------|scroller|---------|Max The position of scroller is set with Value. How do I change the width of scroller? Thank you in advance, Boni
1
by: McDougall, Marshall | last post by:
I have an existing installation of 7.3.4 that appears to have been made with "--without-readline and --without-zlib" parameters used at build time. How do I change those parms without...
0
by: Ian E. Morgan | last post by:
After being frustrated with the inflexible output of intervals, I've written a pl/pgsql function to do what I want, and hopefully some other people might find it useful. Output is a string that...
3
by: shawn | last post by:
Hi All Was trying to get this bit of code working (simplified of course) for (i=0;i<uuid_num;i++) { window.setInterval(InitMap(uuidValues), timePeriod); } Where uuid_num, uuidValues,...
0
by: Shogun | last post by:
I've created a database with RecordsetType Snapshot, so the user can't modify the data displayed on the text boxes. However, I'd like to create a button "Update" that could allow the user to update...
1
by: somebody | last post by:
So I've got this code: function startCalc(one, two, three){ interval = setInterval(calc(one, two, three),1); } function calc(one, two, three){ var element =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.