hilios / jQuery.countdown

The Final Countdown plugin for jQuery
http://hilios.github.io/jQuery.countdown/
MIT License
2.31k stars 720 forks source link

stop event handler not working #298

Open ghost opened 6 years ago

ghost commented 6 years ago

The issue I am having is that the stop event handler is not working. I am able to stop the timer from another JavaScript function. What I am really looking for is to determine how much time is left when the timer is stopped.

Any help will be highly appreciated.

$('#clock').countdown(finalDate, { defer: true }).on('update.countdown', function (event) {
                    if (TestScore == TotalScore) {
                        $("#clock").countdown('stop');
                        ShowTestFinishModal();
                    }
                    else {
                        var format = '%M:%S';
                        if (event.offset.totalDays > 0) {
                            format = '%-d day%!d ' + format;
                        }
                        if (event.offset.weeks > 0) {
                            format = '%-w week%!w ' + format;
                        }
                        $(this).html(event.strftime(format));
                    };
                }).on('finish.countdown', function (event) {
                    IsTestAvailable = false;
                    SaveBlockTestScores();
                    if (TestScore == TotalScore) {
                        $("#clock").countdown('stop');
                        ShowTestFinishModal();
                    }
                    else {
                        $("#messageModal-title").empty();
                        $("#messageModal-body").empty();

                        $("#messageModal-title").append("<h1>Test over</h1>");
                        $("#messageModal-body").append("<h2>You scrore is " + TestScore + ". Please practice assigned cases again and reattempt this test.</h2>");
                        $("#messageModal").modal('show');
                    }
                    }).on('countdown.stop', function () {
                        alert('h');
                    }).countdown('start');
webwamp commented 4 years ago

hi @ashkot123 this is wrong called, you cannot use countdown.stop and you should do this:

$('#clock').countdown("stop);

stop is exactly like start in end of your code