Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does HTML stop the timer?

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report