Get the App
SLTechnology News&Howtos  ›  Development  › 

How does HTML stop the timer?

Shulou Source: shulou.com Published: 2022-06-01 04:08:36 10月05日 Update

Most people do not understand the knowledge points of this article "HTML how to stop timer", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "HTML how to stop timer" article.

The difference between interval and delay timer

Interval timer setInterval (fun,time)

Fun is a function that holds the key.

Time is the time interval of execution (in milliseconds). Every time time, the code of "every fun execution" is executed.

# tim {

Width: 100px

Height: 100px

Background: red

Margin: 0 auto

}

/ / interval timer setInterval executes every three seconds

SetInterval (function () {

Alert ("I am a pop-up window with a delay of 3 seconds")

Console.log (1) / / console output 1 every 3 seconds

}, 3000)

Delay timer setTimeout (fun,time)

Fun is a function that holds the key.

Time is the delay execution time (in milliseconds). After the time time, the fun code is executed only for several times.

# tim {

Width: 100px

Height: 100px

Background: red

Margin: 0 auto

}

/ / delay timer setTimeout will only be executed once

SetTimeout (function () {

Alert ("I am a pop-up window with a delay of 3 seconds")

}, 3000)

Three seconds later:

How to stop the timer

ClearInterval clearance interval timer

# tim {

Width: 100px

Height: 100px

Background: red

Margin: 0 auto

}

/ / clear timer

Var timer1=setInterval (function () {

Console.log ("I am the interval timer")

# time is the delay execution time (in milliseconds). Execute the fun code after the time time, and only execute the memory for several times.

}, 1000)

Var timer2=setTimeout (function () {

Console.log ("I am the delay timer")

ClearInterval (timer1)

# the interval output stops after the interval is executed twice. Here, the interval is cleared in the delay, and the delay output is no longer output after one delay.

}, 2000)

ClearTimeout clears the delay timer (that is, when this delay timer, before its delay time is up, I have executed some code here to determine that the code has been executed, and you don't want to execute this timer)

# tim {

Width: 100px

Height: 100px

Background: red

Margin: 0 auto

}

/ / clear timer

Var timer1=setInterval (function () {

Console.log ("I am the interval timer")

ClearTimeout (timer2)

/ / the original output is an interval of one second and a delay of two seconds. The following delay is not output after the delay is cleared, and the interval continues to output.

}, 1000)

Var timer2=setTimeout (function () {

Console.log ("I am the delay timer")

}, 2000)

The above is about the content of this article on "how to stop the timer of HTML". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Timer output time code content unit function that is article time knowledge article value most console more steps knowledge points industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS vpn Shulou Technology Shulou Tech Info