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

What about multiple setinterval conflicts?

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

Share

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

This article mainly shows you "what to do with multiple setinterval conflicts", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to do multiple setinterval conflicts".

An error occurs when you need to run two setInterval successively in the same function segment (for example, a function). The two are almost parallel at the same time. I don't know how the web page is loaded. Solution: at the end of the intervalA, call another intervalB in the intervalA.

Multiple setInterval conflict issu

For example:

Vart=setInterval (functionA () {

/ / dosomething...

/ / addconditiontoendintervalA

If () {

ClearInterval (t)

T=null

B (); / / callfunctionB

}

}, time)

FunctionB () {

SetInterval (functionC () {

/ / dosth

}, time)

}

How to make multiple setInterval functions execute normally on one page

VarfirstInterval

VarsecondInterval

FunctionfirstAlert () {

If (firstInterval) clearInterval (firstInterval); / / this is the key point

/ / deal with all

.

FirstInterval=setInterval ('firstAlert ()', 1000'2)

}

FunctionsecondAlert () {

If (secondInterval) clearInterval (secondInterval); / / this is the key point

/ / deal with all

.

SecondInterval=setInterval ('secondAlert ()', 1000'3)

}

Such as the above code, the same page using two different frequencies of setInterval can also be used normally, the page will not report errors or jam.

The above is all the contents of the article "what to do with multiple setinterval conflicts". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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