Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause button = resume function #55

Closed
captainscorch opened this issue Oct 30, 2018 · 2 comments
Closed

Pause button = resume function #55

captainscorch opened this issue Oct 30, 2018 · 2 comments

Comments

@captainscorch
Copy link

captainscorch commented Oct 30, 2018

Hello,

thanks for creating the great timer script!
I am aware of the "pause" button from your sample page, my problem is I only have 3 buttons. Start, Pause/Resume and Stop. The Pause button should resume the timer when clicked again after being paused.

I tried to change the class after the click on the pause button from "pauseButton" to "startButton" but this didn't help. Is there anyway to do this?

Here's my HTML:
<div id="controls" class="recordingTime"> <button id="recordButton" class="startButton" onclick="displayStopwatch()"><i class="fas fa-microphone"></i></button> <button id="pauseButton" class="pauseButton" disabled><i class="fas fa-pause"></i></button> <button id="stopButton" class="stopButton" disabled><i class="fas fa-stop"></i></button> </div>

That's my current timer code:
// show recording time var timer = new Timer(); $('.recordingTime .startButton').click(function () { timer.start(); }); $('.recordingTime .pauseButton').click(function () { timer.pause(); }); $('.recordingTime .stopButton').click(function () { timer.stop(); }); timer.addEventListener('secondsUpdated', function (e) { $('.recordingTime .values').html(timer.getTimeValues().toString()); }); timer.addEventListener('started', function (e) { $('.recordingTime .values').html(timer.getTimeValues().toString()); });

@albert-gonzalez
Copy link
Owner

Hi!

You can define a flag and use it to pause/resume the timer using the pause button. Something like this:

var paused = false;
$('.recordingTime .pauseButton').click(function () {
  if (paused) {
    paused = false;
    timer.start();
  } else {
    paused = true;
    timer.pause();
  }
}); 

I hope this helps you.

Best regards!

@captainscorch
Copy link
Author

Hello Albert,

thank you so much for the quick help. This worked perfectly! I appreciate it.
Also, I would suggest to add this code snippet to the documentation as I'm sure more people would like to use the same button for pause & resume.

Anyways, thanks again for the help & developing this easy timer!

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants