JS implementation snapping countdown accurate to milliseconds expiry prompt "snapping is over"

Source: Internet
Author: User
Tags set time

<%@ page language= "java"  contenttype= "Text/html; charset=utf-8"      pageencoding= "Utf-8"%><! doctype html public  "-//w3c//dtd html 4.01 transitional//en"   "HTTP// Www.w3.org/TR/html4/loose.dtd ">

Because the settimeout (expression, delay time) is executed, after the specified time is delayed after loading, the expression is executed once, remember, the number of times is
The setinterval (expression, interaction time) is not the same, it executes the expression once every specified time from loading
So, it's totally different.

Many people are accustomed to include settimeout in the executed function, and then use the settimeout again outside the function to achieve the purpose of timed execution, so that the settimeout outside the function triggers the settimeout again when the function is executed, resulting in a recurring timing effect.

When used, each has its own advantages, using the setinterval, you need to stop the tick trigger manually. The use of nested settimeout in the method, you can no longer call settimeout based on the internal logic of the method is equal to stop the trigger.


SetTimeout only runs once, that is, the set time is triggered to run the specified code, after the end of the run. If the same settimeout command is run again in the running code, it can be run in a loop.
The setinterval is loop-activated, that is, each time interval is set to trigger the specified code. This is the real timer.
SetInterval is simple to use, while settimeout is more flexible, can exit the loop at any time, and can be set to run at an irregular interval, such as the first 1 seconds, the second 2 seconds, the third time 3 seconds ...


Reference article:

http://heisetoufa.iteye.com/blog/269566

Http://www.cnblogs.com/mbtq/archive/2012/10/25/2740023.html

Http://blog.sina.com.cn/s/blog_921bd9650101db4b.html

This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1681402

JS implementation snapping countdown accurate to milliseconds expiry prompt "snapping is over"

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.