Timer
Basic format:
The code copy is as follows:
setInterval(function(){code},1000);
/*
Description: 1.setInterval will return a timer ID value
This is possible to receive. var setId = setInterval(.....);
2. The purpose of receiving setId is to clear the timer.
clearTimeout(setId);
*/
For example
A one-time timer
Format:
The code copy is as follows:
setTimeout(function(){code},1000)
Case:
The code copy is as follows:
var setId = setTimeout(function(){
alert('Execute only once');
},1000);
Title scrolling case
The code copy is as follows:
setInterval(function(){
var title =document.title;
//1~length + 0
document.title = title.substring(1)+tit.substring(0,1);
},1000);
I hope that through this article, friends can have a new understanding of JavaScript timer. If you have any questions, please leave me a message.