简体   繁体   中英

Later.js clear() setInterval()

Im using Later.js setInterval generated in Fc for div value incrementing + 1 every second, except last 10 s in minute in my function for jquery Countdown plugin:

function initializeClock(container, finalDate) {
caller = caller + 1;
var instance = caller;
if (clocks[container]) {

clocks[container].clear();

} finalDate = finalDate.toDate();

var totalSeconds, timer, timeForEnd;

switch (container) {
    case 'timeInstant':
        timer = later.parse.recur().every().second().between(0, 50).second();
        timeForEnd = 10;
        break;
    case 'timeHourly':
        timer = later.parse.recur().every(20).second().except().last().minute();
        timeForEnd = 60;
        break;

saving it

   var clocks = {
timeInstant:"" ,
timeHourly:"" ,
timeDaily: "" ,
timeWeekly: "" ,
timeMonthly:"" ,
timeYear: ""

};

Im calling this every minute:

var intervalInstant = later.parse.recur().every().minute(),
timerInstant = later.setInterval(function () {
    setGame(gameTypes[0]);
    clocks.timeInstant = false;
    initializeClock('timeInstant', moment.utc().endOf("minute"));

}, intervalInstant);

But i have big problem to clear() the interval... I call function again, but old setInterval still increment div so it works only first minute, every next minute +2 , + 3 etc

How to stop the later.setInterval( fce, timer) and make a new one?

I was trying it like on docs here, but no effect... Later docs

sorry... I close it to if and solved :) Have a nice day guys...

 if ( !clocks[container]){
    clocks[container] = later.setInterval(function () {
    setBet(container, instance);
}, timer);}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM