Search code examples
javascriptflipclock

Restart FlipClock after time expire


How can I restart flipclock again after time completed?

var clock;

$(document).ready(function() {
    clock = new FlipClock($('.clock'), 10, {
        clockFace: 'Counter',
        autoStart: true,
        countdown: true
    });

});

I want to start again the counter after 10 sec on a condition. What I have tried is

var clock;

$(document).ready(function() {
    clock = new FlipClock($('.clock'), 10, {
        clockFace: 'Counter',
        autoStart: true,
        countdown: true,
        callbacks: {
            stop: function() {
               //my custom condition here if(not_free){start showing again}
                clock.start();
            }
        }
    });

});

But this not worked. any idea?


Solution

  • Try to add this line into the stop callback function.

    clock.setTime(10);
    

    Final codes:

    var clock;
    
    $(document).ready(function() {
        clock = new FlipClock($('.clock'), 10, {
            clockFace: 'Counter',
            autoStart: true,
            countdown: true,
            callbacks: {
                stop: function() {
                    clock.setTime(10);
                    clock.start();
                }
            }
        });
    
    });