Page 2 of 3

stop countdown timer

Posted: Mon Apr 06, 2015 9:47 pm
by Mike6979865

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!

stop countdown timer

Posted: Tue Apr 07, 2015 9:17 pm
by Mike6979865

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


stop countdown timer

Posted: Wed Apr 08, 2015 12:13 am
by Yurii Orishchuk

Hi Mike,

Thanks for this update.

Glad it works.

Regards.


stop countdown timer

Posted: Thu Jun 18, 2015 6:21 pm
by Mike6979865

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.


stop countdown timer

Posted: Sat Jun 20, 2015 3:52 pm
by Alena Prykhodko

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.


stop countdown timer

Posted: Thu Jan 14, 2016 8:34 pm
by Ser Bronn

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();


stop countdown timer

Posted: Fri Jan 15, 2016 7:47 am
by Evgene Karachevtsev

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.


stop countdown timer

Posted: Sat Jan 16, 2016 7:07 am
by Ser Bronn

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()


stop countdown timer

Posted: Mon Jan 18, 2016 10:46 am
by Serhii Kulibaba

Hello,

You can stop this with JS code below:

window.countDownInterval.clearInterval();


stop countdown timer

Posted: Tue Jan 19, 2016 6:44 am
by Ser Bronn

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