Как я мог остановить этот таймер вручную с помощью Jquery - PullRequest
0 голосов
/ 19 сентября 2019

Так что я смотрю вокруг и все еще не могу найти ответ, я пытаюсь остановить таймер, который я вызываю в окне через плагин, дело в том, что он не останавливается и продолжается послефункция stopTimer вызывается ...

$.fn.startTimer = function(startTime, maxTime) {
    var presets = {
        starting: new Date(),
        startTime: 60000,
        maxTime: 60000,
        left: 0};
    if (!startTime)
        startTime = presets[startTime];
    if (!maxTime)
        maxTime = presets[maxTime];
    var timeoutVal = Math.floor(maxTime / 100);
    this.Timer = null;
    animateUpdate();
    function updateProgress(percentage) {
        if (me == true)
            $('.turnText').html("TURN #" + turn + " ENDING IN " + Math.round(presets['left'] / 1000) + " SECONDS");
        $('.timerBar.Left').slideDown('slow').css('width', percentage + '%');
    }
    function animateUpdate() {
        var now = new Date();
        presets['left'] = (presets['starting'].getTime() + startTime) - now.getTime();
        var perc = Math.round((presets['left'] / maxTime) * 100);
        if (perc >= 0) {
            updateProgress(perc);
            Timer = setTimeout(animateUpdate, timeoutVal);
        } else {
            $('.turnText').html("Ending turn...");
            if (me == false)
                location.reload();

            $(window).stopTimer();// Not working
            if (me == true)
                $('form[name=turn-' + turn + ']').submit();
        }
    }
};
$.fn.stopTimer = function() {
    clearTimeout(this.Timer);
    this.Timer = null;
}

и в моем коде окна я называю это

$(window).startTimer();

$(window).stopTimer(); // doesn't work..
´´´

Please help!!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...