Summary of JavaScript Timer Types

Summary of JavaScript Timer Types

1.setInterval()

Calls the function at a specified interval (in milliseconds).

The method will keep calling the function until clearInterval() is called or the window is closed.

grammar:

setInterval(code,millisec,[arg1, arg2, ...])

parameter describe
code Required. The code string to execute.
millisec must. The time interval in milliseconds.
arg1, arg2, … Optional. When the timer expires, additional parameters will be passed to the function specified by func

2.setTimeout()

Calls a function after the specified number of milliseconds.

grammar:

setTimeout(code,millisec,[arg1, arg2, ...]); //parameters have the same function as above

Final code demonstration:

//1. You can write setTimeout directly using arrow function(()=>{
 this.isSkeleton=false;
  },2000)
 
//2. You can return a value and then call clearTimeout() to cancel the timer;
let a = setTimeout(()=>{
  alert('popup');
  },5000);
function b() {
  window.clearTimeout(a); // Pop-up window appears after 5 seconds, calling b function can directly cancel the pop-up.}

Return value:

The return value intervalID is a non-zero value used to identify the timer created by setInterval() . This value can be used as a parameter of clearInterval() to clear the corresponding timer. Note that setInterval() and setTimeout() share the same ID pool, so avoid mixing them.

Finally, some knowledge:

JS objects can be obtained in two ways: one is customized by the developer; the other is provided by ECMAScript . The objects provided by ECMAScript are called JavaScript built-in objects.

The timer is provided by window object, and window call can also be added before the timer.

This is the end of this article about the summary of JavaScript timer types. For more information about JavaScript timer types, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of the JavaScript timer principle
  • Detailed explanation of JavaScript timers
  • JavaScript Timer Details
  • JavaScript timer to achieve limited time flash sale function
  • JavaScript timer to achieve seamless scrolling of pictures

<<:  Solution to PHP not being able to be parsed after nginx installation is complete

>>:  How to solve the problem of not getting form value after submitting html form input using disabled

Recommend

Recommend a cool interactive website made by a front-end engineer

Website link: http://strml.net/ By Samuel Reed Ti...

Faint: "Use web2.0 to create standard-compliant pages"

Today someone talked to me about a website develo...

Summary of the use of html meta tags (recommended)

Meta tag function The META tag is a key tag in th...

mysql row column conversion sample code

1. Demand We have three tables. We need to classi...

How to build a MySQL high-availability and high-performance cluster

Table of contents What is MySQL NDB Cluster Preli...

Summary of basic SQL statements in MySQL database

This article uses examples to describe the basic ...

An article to understand Linux disks and disk partitions

Preface All hardware devices in the Linux system ...

Design Reference Beautiful and Original Blog Design

All blogs listed below are original and uniquely ...

Use of MySQL trigger

Table of contents 1. Trigger Introduction 1. What...

HTML unordered list bullet points using images CSS writing

Create an HTML page with an unordered list of at l...

Example code for implementing auto-increment sequence in mysql

1. Create a sequence table CREATE TABLE `sequence...

Introduction to html form control disabled attributes readonly VS disabled

There are two ways to disable form submission in ...

In-depth analysis of MySQL 8.0 redo log

Table of contents Preface Generation of redo log ...