How to Implement the pause and continue timer in JavaScript

Source: Internet
Author: User
This article mainly introduces the related information about the methods for pausing and resuming the timer in JavaScript, which is very good. If you need it, you can refer to it. For JavaScript timers, there is no strict pause or restart, only the stop is cleared, but it can be implemented through some 'blind-eye method '.

AllChild [index]. onclick = function () {// when the target is clicked and the following conditions are met, set the timer time to suspend if (gamInt = true) {$ ("# tu" ).css ("display", "block"); // timer pause (clear timer) clearInterval (countdownTimer ); // after a latency of 2 seconds, the game continues to pause the timer and ends. setTimeout (function () {// remove all images removeImgFun (); $ ("# tu" ).css ("display ", "none"); imgNum ++; if (imgNum> = 10) {imgNum = 10;} createImgFun (); // The timer is added before it is connected (the previous timer is re-referenced to include the name of the timer once (it must be available or it is easy to cause computer crashes) countdownTimer = setInterval (Function () {countdownNum-= 0.01; // retain two decimal places countdownNum = countdownNum. toFixed (2); if (countdownNum <= 0) {clearInterval (countdownTimer); // the game ends alert ("the game ends! "); // The ancestral home name cannot be clicked (score no longer counted) gamInt = false;} time. innerHTML = "Countdown:" + countdownNum + "seconds" ;}, 10) ;}, 2000) // score scores + = 1; score. innerHTML = "" + scores + ""; if (scores> 8) {$ ("# wc" ).css ("display", "block "); $ ("# haha" ).css ("display", "none"); $ ("# cj "). on ("click", award (); $ ("# sm "). on ("click", explain ());}}}

The above is a small Editor to introduce you to the JavaScript pause and continue timer method, I hope to help you, if you have any questions, please leave a message, the small editor will reply to you in a timely manner. I would like to thank you for your support for PHP chinnet!

For more articles about how to implement JavaScript pause and continue timer, please follow the PHP Chinese network!

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.