How to implement JavaScript pause and resume timer _javascript tips

Source: Internet
Author: User

There is no strict pause and restart for JavaScript timers, only cleanup stops, but can be implemented with some ' cloaking '

 Allchild[index].onclick = function () {///Let the timer pause if (Gamint = True) {$ ("#tu" when clicking on the target and satisfying the conditions below)
"). CSS (" Display "," block ");
Timer paused (Clear timer) clearinterval (Countdowntimer); Delay after 2s game continue timer pause End settimeout (function () {//Remove All pictures Removeimgfun (); $ ("#tu"). CSS ("display", "none"); imgnum++; if (
Imgnum >=) {imgnum = ten;} createimgfun ();
The timer continues to pick up the time before the increase continues to play (the previous timer is referred to again including the name of the timer (must have a computer crash) Countdowntimer = setinterval (function () {
Countdownnum-= 0.01;
Retains two decimal countdownnum = countdownnum.tofixed (2); if (countdownnum <= 0) {clearinterval (Countdowntimer);//End of Game alert ("Game Over!")
");
Jaycee name can not be clicked again (score no longer count) Gamint = false;
time.innerhtml = "Countdown:" + Countdownnum + "seconds";},10)},2000)//scoring scores + 1;
score.innerhtml = "The first" + scores + "off";
if (Scores > 8) {$ ("#wc"). CSS ("Display", "block"); $ ("#haha"). CSS ("display", "none"); $ ("#cj"). On ("Click", award ());
$ ("#sm"). On ("Click", Explain ()); }
}
}

The above is a small set of JavaScript to introduce the pause and continue the timer method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.