Mike6979865
Posts: 0
Joined: Fri Jul 11, 2014 3:53 pm

stop countdown timer

Hi, I'm using this code below, and it's working perfectly fine. So, when I click a button, I'm running the HTML. However, when I click on the popup and close it, the timer is still running. How can I stop it once i exit the popup.

function startTimer(duration, display) {
var start = Date.now(),
diff,
minutes,
seconds;
function timer() {
// get the number of seconds that have elapsed since
// startTimer() was called
diff = duration - (((Date.now() - start) / 1000) | 0);

Code: Select all

     // does the same job as parseInt truncates the float 
     minutes = (diff / 60) | 0; 
     seconds = (diff % 60) | 0; 

     minutes = minutes < 10 ? "0" + minutes : minutes; 
     seconds = seconds < 10 ? "0" + seconds : seconds; 

     display.textContent = minutes + ":" + seconds;  

     if (diff  
 Registration closes in span/span minutes!
Mike6979865
Posts: 0
Joined: Fri Jul 11, 2014 3:53 pm

stop countdown timer

Resolved... I referred to this solution: https://getsatisfaction.com/apperyio/...

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

stop countdown timer

Hi Mike,

Thanks for this update.

Glad it works.

Regards.

Mike6979865
Posts: 0
Joined: Fri Jul 11, 2014 3:53 pm

stop countdown timer

Hi, so I have this code below for the count down timer:

var seconds = 0;
var minutes = 5;

var secondPassed = function() {

Code: Select all

 Appery("timer_div").text(minutes + " : " + seconds); { 
     seconds--; 
     if (seconds === 0) { 
         if (minutes === 0) { 
             //var chad = function() { 
                 clearInterval(countdownTimer); 
                 Appery("timer_div").text("timer done"); 
                 //getRandomInt(min, max); 
             //    return Math.floor(Math.random() * (max - min)) + min; 
             //}; 
             var imageUrl = Appery.getImagePath("timeup.jpg"); 
             StopPlayTrack(); 
             Apperyio("mobileimage_27").attr("src", imageUrl); 
         } else { 
             seconds = 60; 
             minutes--; 
         } 
     } 
 } 

};
clearInterval(self.countdownTimer);

self.countdownTimer = setInterval(secondPassed, 1000);
secondPassed();

It work fine, however, it's showing this for example when I input 2 min and 60 sec.

2:60
2:59
.
.

I want it to show 3:00, 2:59,2:58...

Can you please assist? Thanks again.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

stop countdown timer

Hello Mike,

Custom code is something outside the scope of our support.
Unfortunately we do not have ready solution. Probably someone from community has and will share.
Also you can search online for appropriate code example.

Ser Bronn
Posts: 0
Joined: Thu Jan 14, 2016 7:38 am

stop countdown timer

Do you have to setup a Server Code Script to get the above countdown timer code to work? I've tried every way without setting up a server code script but it won't work.

-----------------

var count=10;
//It will fix two clicks on the button.
clearInterval(window.countDownInterval);
window.countDownInterval = setInterval(timer, 1000); //1000 will run it every 1 second
function timer()
{
Appery("countdown").text(count);
count=count-1;
if(count < 0)
//Stop interval.
clearInterval(window.countDownInterval);
};
timer();

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

stop countdown timer

Hello Ser,

Please try this: codecounter&#46;clearInterval();/code
This will remove your setInterval timer and then if you need you can recreate it as you mentioned before.

Ser Bronn
Posts: 0
Joined: Thu Jan 14, 2016 7:38 am

stop countdown timer

What line does that code go on?
This line? window.countDownInterval = setInterval(timer, 1000); //1000 will run it every 1 second

Replace it with counter.clearInterval()

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

stop countdown timer

Hello,

You can stop this with JS code below:

window.countDownInterval.clearInterval();

Ser Bronn
Posts: 0
Joined: Thu Jan 14, 2016 7:38 am

stop countdown timer

Right now I have this on the start button:
//It will fix two clicks on the button.
clearInterval(window.countDownInterval);
window.countDownInterval = setInterval(timer, 1000); //1000 will run it every 1 second
function timer()
{
Appery("countdown").text(count);
count=count-1;
if(count < 0)
//Stop interval.
clearInterval(window.countDownInterval);
}
timer();

And I have this on the Stop button:
//It will fix two clicks on the button.
window.countDownInterval.clearInterval();
//Please replace "Initial countdown value." with initial value you need. Or remove this line if you don't want to change value to initial.
Appery("countdown").text("10.");

It's still not starting or stoping. The count variable=10 is showing on the display.

Where lines does counter.clearInterval(); go on the Start button script go?
Thanks for your help

Return to “Issues”