Home > Web Front-end > JS Tutorial > body text

Detailed explanation of JS timer function examples

怪我咯
Release: 2017-06-29 10:46:54
Original
1674 people have browsed it

This article mainly introduces the relevant information of javascript timer in detail. It is very comprehensive and detailed. Friends in need can refer to

Timer

Basic format:

The code is as follows:

setInterval(function(){代码},1000);
/*
说明:1.setInterval 会返回一个计时器ID值
   可以这样接收。var setId = setInterval(....);
 2.接收setId的目的是为了清空计时器。
   clearTimeout(setId);
*/
Copy after login

For example


One-time timer

Format:

The code is as follows:

   setTimeout(function(){代码},1000)
Copy after login

Case:

The code is as follows:

        var setId = setTimeout(function(){
         alert('只执行一次');
        },1000);
Copy after login

Title scrolling case

The code is as follows:

setInterval(function(){
     var tit =
document
.title;
    //1~length    +  0  
    document.title = tit.sub
string
(1)+tit.
substr
ing(0,1);
      },1000);
Copy after login

The above is the detailed content of Detailed explanation of JS timer function examples. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template