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