objectivehtml / FlipClock

http://flipclockjs.com/
MIT License
2.74k stars 954 forks source link

When the countdown ends, it doesn't stop #415

Open slmholder opened 3 years ago

slmholder commented 3 years ago

"flipclock": "^0.10.8",

import React from 'react' import './compiled/flipclock.css' import FlipClock from 'flipclock'

const el = document.getElementById('myClock') const nowSeconds = new Date().getTime() / 1000; const end = new Date((nowSeconds + this.state.countDownTime) * 1000) this.clock = new FlipClock(el, end, { face: 'DayCounter', countdown: true, autoStart: true, callbacks: { stop: function() { this.props.getDownloadList(this.state.ID) } } });

To zero but continues to operate as a negative value Is it because I configured it? thank you

tbone849 commented 3 years ago

Hey I had trouble with this also. Just figured out a solution. I used underscore forEach, but you can iterate however you want. It basically checks the face values to see if they are all 0's. If they are, I manually stop the timer.

timer = new FlipClock(el, end, {
    countdown: true,
    showLabels: false,
    autoStart: false
});

timer.start();
timer.$timer.on('interval', function(){
    var complete = true;
    _.forEach(timer.$face.$value.$digits, function(time){
        _.forEach(time, function(digit){
            if(Number.parseInt(digit, 10) > 0){
                complete = false;
            }
        });
    });

    if(complete){
        timer.stop();
    }
});
slmholder commented 3 years ago

@tbone849 Thank you very much for your thoughts. The problem has been solved. Thanks again.