猿问

如何获得播放按钮以在 Javascript 上继续计时器?

我试图简单地让我的播放按钮起作用,但我不知道如何。我通过添加clearInterval(timer)让我的暂停按钮工作,所以我猜我做了相反的事情?


我曾尝试加入countDown对playTimer功能tick的addEventListener,但那些不工作。


var startButton = document.getElementById("start");

var startSound = document.getElementById("audio"); 

var timerSound = document.getElementById("timer");

var counter = document.getElementById("counter");

var pausePlay = document.getElementsByClassName("pausePlay");

var pauseButton = document.getElementById("pause");

var playButton = document.getElementById('play');

var middleButtons = document.getElementsByClassName("middleButtons");

var fiveMin = document.getElementById("fiveMin");

var end = document.getElementById("endSess");

var redo = document.getElementById("redo");



function playAudio(){

    startSound.play();

}


// Start button will disappear after click and countDown method will begin

function startTimer(){

    startButton.style.display="none"; 

    counter.style.display = "";

    for (var i = 0; i < pausePlay.length; i++) {

        pausePlay[i].style.display = "block";

      }



    countDown(10);

}

// function play(){


// }


function countDown(minutes){

    var seconds = 60;

    var mins = minutes;

    function tick(){


        var current_minutes = mins - 1;

        seconds --;


        counter.innerHTML = current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);

        if(seconds > 0){

            timer = setTimeout(tick, 1);

        } else {

            if(mins > 1){

                countDown(mins - 1);

            }

            else if (mins && seconds === 0 ){

               timerSound.play();

               for (var i = 0; i < pausePlay.length; i++){

                pausePlay[i].style.display = "none";

                }

                options();

            }

        }

    }    

    tick();

  }

// Pause timer

  function pauseTimer(){

    clearInterval(timer);


  }

// Continue timer

function playTimer(){

    countDown();

}



月关宝盒
浏览 118回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答