Javascript Timer Setinterval,settimeout,clearinterval

Source: Internet
Author: User

Today, to open a blog, to 1, wow ha ha ~ ~

Today would like to review the BOM to see the timer is also counted Dom one? (Is that right), share

References from: Eight Gods kiss You http://www.cnblogs.com/lmfeng/archive/2011/06/24/2089237.html

One-time timer is executed

1     //One-time timer is executed2 3SetInterval (Console.log (1), 1000);//performed 1 times4 5 //------------------------------------6 7     varA =function(){8Console.log (1);9     };Ten  OneSetInterval (A (), 1000);//performed 1 times A  - //------------------------------------ -  theSetTimeout (Console.log (1), 1000);//performed 1 times

One time delay timer

1 // one time delay timer 2     var a = 0; 3     var b = setTimeout (function() {4         a++; 5         Console.log (a);                             // assignment interval wait time execution 6     },1000);

multiple timer and clearinterval removal timer

1 //multiple executions and clearinterval removal timers2     varA = 0;3     varb = SetInterval (function(){4a++;5 Console.log (a);6         if(A = = 5) {clearinterval (b)}//clearinterval7},1000);//executes multiple times

SetInterval syntax

SetInterval (function,interval[,arg1,arg2,...... argn])

1     function Show (str) {                             //arguments2        console.log (str)3      }45     setinterval (show,1000,111);                     // arguments

SetInterval (object,methodname,interval[,arg1,arg2,..... argn]) ★ This to be continued

In addition before in Xin Space See, Requestanimationframe (), Sensory method class is, this also to be continued 、-。 *

Finally share a time-out code, write not meticulous, just provide ideas, have small partners to improve hope can also share to me

1 // Countdown 2     var num = ten; 3     var settime = setinterval (function() {4         num--; 5         console.log (num); 6         if (num = = 0 ) clearinterval (settime); 7     },1000)

Javascript Timer Setinterval,settimeout,clearinterval

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.