The function of SetTimeout and setinterval is a specified event or method that occurs after a certain time period.
The Window.settimeout method is a timed procedure, that is, what to do after a certain time,
Window.setinterval ()
Function: Invokes a function or evaluates an expression by the specified period (in milliseconds).
Syntax: SetInterval (CODE,MILLISEC)
Explanation: Code: The JavaScript code string to be executed at timed time.
MILLISEC: The set timing time, expressed in milliseconds.
Return value: The ID value of the timer, which can be used for the Clearinterval () method to stop the specified timer.
Note: the SetInterval () method keeps calling functions until the timer is terminated with clearinterval () or the window is closed.
Window.clearinterval ()
Function: Cancels the timer set by the SetInterval () method.
Syntax: Clearinterval (Id_of_setinterval)
Explanation: Id_of_setinterval: The ID value returned by setinterval (). This value identifies a setinterval timer.
That is, Window.setinterval () returns the Window.clearinterval parameter.
The difference between the two:
Window.settimeout ("function", time);//Set a timeout object, execute once, no cycle
Window.setinterval ("function", time);//Set a timeout object, period = ' interaction times '
Stop timing:
Window.cleartimeout (object) clears the SetTimeout object that has been set
Window.clearinterval (object) clears the SetInterval object that has been set
SetTimeout (expression, delay time);
SetInterval (expression, interaction time);
Delay Time/Interaction time is in Hao seconds (1000ms=1s)
The two expressions are very similar, but the function is very different, from the expression of the parameters can also be seen:
SetTimeout executes an expression once after it has been delayed for a specified time after loading and executes only once
SetInterval executes an expression once every specified time from loading, when it is executed
The difference between window.settimeout usage and window.setinterval usage