The thing is, I added a couple of intervals to the setInterval page, slider, etc. And already the page inadequately behaves "buggy" slightly, I can not understand the problem, I leave even just one setInterval on the page, but somehow the site behaves in a wrong way, although nothing bad happens. In the interval, simply b ++ if (b> c) b = 1; The loop itself is endless for a slider.

So prescribe setInterval:

var b = 1; var c = 10; var time = 3000; function loadednext() { b++; if (b > c) { b = 1; } } var inter = setinterval(loadednext, time); 
  • Let me guess - setInterval is written with parameters in quotes, am I right? If yes - rewrite, if not - provide code - Zowie
  • I fixed how I use it, and how can I do without it in more detail? - Afimida
  • wouldn't the setTimeout function have less impact on the performance of the js code on the client side? - Afimida
  • @Spectre setInterval by itself should not slow down the page. If the action must be performed continuously, then using setTimeout is at least not logical - Zowie
  • Actually, in the setInterval itself, only a couple of changes of css properties are performed, as well as animate - Afimida

1 answer 1

In most cases, you can do without setInterval

 function someFunction() { ... setTimeout(function () { someFunction(); }, 500); } 

How JavaScript Timers Work

JavaScript Garden: setTimeout and setInterval recommend avoiding setInterval

  • function someFunction () {... setTimeout (function () {someFunction ();}, 500); } How JavaScript Garden Timers work JavaScript: setTimeout and setInterval recommend avoiding setInterval As if I was not surprised, but it helped! Thank you very much - Afimida
  • one
    Those. You want to say that you use such code as you wrote above and it led to the brakes during setInterval and stopped without it? Either you keep back something or I don’t understand anything in javascript'e - Zowie
  • I want to say that we both don’t understand something, however, with this approach and according to the proposed literature, setTimeout will not break into a breach to execute its part of the code, and will not slow down the code, unlike setInterval, well, I will repeat it again If you believe the literature, but judging by what I saw the lags became noticeably lower. - Afimida
  • 2
    I dare to assume that you have huge problems with the wording of the question, this erysipelas interval cannot noticeably (noticeably for the human eye, even in the debager, you practically would not notice the difference), of course, if the code was not written through the terrible F and the adequate was done work interval. - Zowie
  • one
    If I have the opportunity to beat off my hands I will definitely do it, the whole problem was this: background-size: cover; -moz-background-size: cover; It was this that severely put pressure on the browser (((It’s a pity it’s impossible to put minuses on your own (^_^) - Afimida