Causes and Solutions of the First Delay of js Timer
- 2021-10-16 00:46:34
- OfStack
When we use js timer, it often happens that we get data every few seconds, which is realized through setInterval. And if the setInterval () parameter is improperly passed, the timer will delay the trial. This paper introduces the principle and implementation process of the first delay of js timer.
setInterval()
The function is to call a function, method or object every 1 fixed time when playing animation.
Grammar
setInterval(function(),time); In milliseconds
Note: The unit is milliseconds
The first delay execution of timer: implemented by setInterval
var t = setInterval(scrollTop,2500);
function scrollTop(){
// ...
}
Solution to the delay in the first execution of js setInterval
When you use the setInterbal (function, delayTime) method, you find that it also delays the first call of the function. 1 All of us call immediately for the first time, and then delay the call. My solution is as follows:
Functions that need to be called late:
function callinSound(){
var callin=$('#callin')[0];
callin.load();
callin.play();
// No. 1 1 This function is returned after the second execution is completed
return callinSound;
}
Caller: setInterval(callinSound(),6000);
First, call the callinSound () method, and then deferred execution.