Timer settimeout () and SetInterval () two are all JS functions of the timing function two a little different.
SetTimeout ():
Explanation in the JS manual: used to call a function or evaluate an expression after a specified number of milliseconds;
That is, execute after the set number of seconds is completed.
Experiment code (change body background color):
Copy Code code as follows:
settimeout (function () {
$ ("Body"). CSS ("Background", "Red");
},5000);
SetInterval ():
Explanation in the JS manual: Call a function or a calculation expression according to the specified period (in milliseconds). The function is called continuously until the Clearinterval () is called or the window is closed;
Execute your own effect code or function in the number of seconds you set.
Experimental code (a few seconds of experiment):
Copy Code code as follows:
<div class= "Clock" ></div>
<script>
var num = 0;
SetInterval (function () {$ (". Clock"). HTML (num++)},1000);
</script>
Summarize:
The settimeout () method executes the function after waiting for a specified time, and executes only one incoming handle function.
The SetInterval () method executes an incoming handle function after each specified interval, looping until the window or clearinterval () is closed.