JQuery,启动停止计时器

JQuery,启动停止计时器,jquery,timer,Jquery,Timer,我有一些计时器功能,有分和秒,我的问题是从“clearInterval”或任何其他方式停止的地方运行计时器。。首先,我需要使用rM和rS的值再次运行“启动”函数,这是在我停止它的那一刻,但我不知道如何运行。只是在恢复时不设置rM和rS function start() { rM = Math.floor((Math.random() * 1) + 1); rS = Math.floor((Math.random() * 59) + 1); $('#minutes'

我有一些计时器功能,有分和秒,我的问题是从“clearInterval”或任何其他方式停止的地方运行计时器。。首先,我需要使用rM和rS的值再次运行“启动”函数,这是在我停止它的那一刻,但我不知道如何运行。

只是在恢复时不设置rM和rS

    function start() {
    rM = Math.floor((Math.random() * 1) + 1);
    rS = Math.floor((Math.random() * 59) + 1);
    $('#minutes').text(rM);
    $('#seconds').text(rS);

int1 = setInterval(function timer() {
    if(rM > 0 && rS > 0) 
    {
        rS--;
        $('#seconds').text(rS);
    }

    if(rM > 0 && rS == 0) 
    {
        rM--;
        rS = 3;
        $('#minutes').text(rM);
        $('#seconds').text(rS);
    }

    if(rM == 0 && rS > 0) 
    {
        rS--;
        $('#seconds').text(rS);
    }

    if(rM == 0 && rS == 0) 
    {
        $('#minutes').text(rM);
        $('#seconds').text(rS);

        function timerChange() {
            if(myGallery.imgIndex != myGallery.indexMax)
            {
                myGallery.imgIndex++;
                changeNext();
                btnNext.disabled = false;

                rM = Math.floor((Math.random() * 1) + 1);
                rS = Math.floor((Math.random() * 59) + 1);
                $('#minutes').text(rM);
                $('#seconds').text(rS);
            }

            else
            {
                myGallery.imgIndex = 1;
                changeNext();
                btnNext.disabled = false;   

                rM = Math.floor((Math.random() * 1) + 1);
                rS = Math.floor((Math.random() * 59) + 1);
                $('#minutes').text(rM);
                $('#seconds').text(rS);
            }
        }

        timerChange();

    }


}, 1000);


};  

    $('#pause').click(function()
    {
        if(paused == false)
        {

            clearInterval(int1),
            paused = true;
        }

        else
        {

            //some code to start timer again
            paused = false;
        }
    });

start();
参见小提琴:

        function start(resume) {
            if (!resume) {
                rM = Math.floor((Math.random() * 1) + 1);
                rS = Math.floor((Math.random() * 59) + 1);
            }
        ...


       $('#pause').click(function () {
            if (paused == false) {
                clearInterval(int1);
                paused = true;
            }
            else {
                //some code to start timer again
                paused = false;
                start(true);
            }
        });