Get the App
SLTechnology News&Howtos  ›  Development  › 

What about multiple setinterval conflicts?

Shulou Source: shulou.com Published: 2022-06-03 11:01:51 11月12日 Update

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!

Tags: Multiple conflict what to do content function article page two time focus processing learning help different code sequence at the same time such as above scheme easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Shulou Information Docker macOS