473,396 Members | 1,764 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,396 software developers and data experts.

Pause button

I have images and text rotating every 7000 ms using a setInterval. i am trying to implement a pause button that will stop the rotation when clicked. When clicked once more, I would like the rotation to continue.

The first time that the pause button is clicked, the rotation stops and all is well. Click again and the rotation continues. But then i can't seem to pause thereafter. Where am i going wrong?


Expand|Select|Wrap|Line Numbers
  1. function pause() {
  2. switch (p) {
  3. case 0:
  4. document.pausebutton.src="images/pause_on.gif";
  5. window.clearInterval(timer);
  6. window.clearInterval(timer2);
  7. p=1;
  8. break;
  9. case 1:
  10. document.pausebutton.src="images/news.gif";
  11. var timer2=window.setInterval("section()", 7000);
  12. p=0;
  13. break;
  14. }
  15. }
  16.  
  17.  
  18. var timer=window.setInterval("section()", 7000);
  19.  
[HTML]<img name="pausebutton" onclick="pause();" src="images/news.gif" border="0" height="17" width="17" />[/HTML]
Jul 3 '07 #1
3 2583
gits
5,390 Expert Mod 4TB
hi ...

your variable p is undefined ... so the script stops due to an js-error and not clearing the interval. you should init a global variable p with 0 and everything is ok ;)

kind regards
Jul 3 '07 #2
ah sorry i neglected to show that part of the code. i had set var p to 0 earlier in the script. any other ideas??
Jul 3 '07 #3
gits
5,390 Expert Mod 4TB
hmmm ... ahhhhhhhrg ;) ... var timer2 is declared locally ... reuse timer or declare timer2 globally too

Expand|Select|Wrap|Line Numbers
  1. function pause() {
  2.         switch (p) {
  3.         case 0: 
  4.                 document.pausebutton.src="images/pause_on.gif";
  5.                 window.clearInterval(timer);
  6.                 p=1;
  7.                 break;
  8.         case 1: 
  9.                 document.pausebutton.src="images/news.gif";
  10.                 timer=window.setInterval(function() { // do something }, 700);
  11.                 p=0;
  12.                 break;
  13.         }
  14. }                    
  15.  
  16. var timer=window.setInterval(function() { // do something }, 700);
  17.  
kind regards ...
Jul 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brian.Steele | last post by:
Greetings everyone. See http://www.spiceisle.com/cgi-bin/slideshow/slideshow.cgi?dir=brian/personal/2005/uk_trip/images&type=jpg The "Pause" button works in IE, but not in Firefox. Any ideas...
3
by: jdph40 | last post by:
In Access 2002, I designed a simple database for our Safety department to enter results of a survey. There are 41 true/false statements. I have a main form called frmSurvey with a subform called...
8
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause...
3
by: JimJam | last post by:
Hello Peeps I have created a program in VB.NET 2003 that counts down from 7.5 hours to zero from 08:00. I have a button that starts a new countdown from 1 hour to zero whilst the first one is...
6
by: Peted | last post by:
Hi wondering what is the best way to do this Need a user to click a button, that sends 3 or 4 string based commands via a TCP/ip socket link I can connect to the ip device no problems, am...
3
by: nma | last post by:
Hi This code goes well with play, stop and fullscreen button, the only thing is the pause button is not there. How to make pause button? I try to make pause button but when it streams video, when...
2
by: keeplearning | last post by:
Hi Friends ! Please view this ANIMATION . I want to control this animation with a play and pause button . when clicked on play button , the animation should start playing . and when clicked...
6
by: abie16 | last post by:
Hello All, I have created a page with timer for the employee. They need to click start and stop button when doing their work. I want to have a pause button so when they going for break or anything...
5
BradleyJS
by: BradleyJS | last post by:
Hi I have an assignment for school and i was just wondering can someone help me to complete it correctly. It is a memory game that has a timer included and i have got a play button that when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.