473,469 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pause button

14 New Member
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 2585
gits
5,390 Recognized Expert Moderator Expert
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
garfunkel214
14 New Member
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 Recognized Expert Moderator Expert
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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,...
1
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.