Questions tagged [setinterval]

setInterval is a global JavaScript method. It is used to execute a particular function or piece of code at regular intervals.

Tag usage

The tag is appropriate for questions involving the setInterval method.

Implementation

The primary implementation of setInterval receives as arguments a JavaScript function and a number indicating the number of milliseconds in the interval. Ideally, the function would run at the given interval, but this is not always the case if the execution of the function takes longer than the interval. In such a case, MDN recommends using setTimeout instead.

The first parameter to setInterval may also be a code string instead of an actual function, but this usage is generally not recommended for the same reasons that using eval() is frowned upon.

References

4714 questions
1
vote
1 answer

Prevent setinterval() from reset on every page load

I am creating one Web Application in C# MVC and i want one features for play beep at every time interval which i have defined in variable. I'm using setInterval() function of javascript in layout page but it is called on every page load and…
Bharat
  • 93
  • 11
1
vote
1 answer

JavaScript: How Do I Prevent A User From Crashing setInterval / setTimeout Event?

To see the problem click on https://jsfiddle.net/kjz1myL2/16/ and when the fade is complete move your mouse from button to button REALLY FAST. Is there a way to prevent events from crashing or reset them when they crash? I made a JavaScript event…
1
vote
2 answers

Javascript setInterval doesn't work with this. objects

I'm having a problem with the setInterval() Method in Javascript. My main class: var sq1 = new Square(20, 20); window.onkeydown = function (e) { var key = e.keyCode ? e.keyCode : e.which; if (key == 38) { sq1.moveUp(); …
Damien Flury
  • 769
  • 10
  • 23
1
vote
0 answers

JavaScript callback function in setInterval is blocked, and how to do with it?

I get an interview question. I abstract it as below: If you call setInterval, and the callback (or parameter) function is blocked, what should you do? setInterval( () => { someFunction(); // ? What should I do if someFunction is blocked },…
soarinblue
  • 1,517
  • 3
  • 21
  • 30
1
vote
1 answer

clearInterval not working after longer keydown with arrow key

Using setInterval and scrollLeft for a container with images works well with html-buttons. Next i want to use the keyboard arrow-keys but it seems that when you press the arrow-keys too long, the clearInterval doesn't work. There might be…
Ben
  • 110
  • 11
1
vote
3 answers

fullpagejs pause on hover

js and I want to pause the slider when mouse hover the h1 tag but it doesn't, I know that it's a problem with javascript but I'm not able to make it works http://jsfiddle.net/2dhkR/405/ $(document).ready(function() { $('#fullpage').fullpage({ …
colapsnux
  • 872
  • 2
  • 15
  • 32
1
vote
0 answers

data takes time to reflect in google gauge even though the data is loaded

I have written the below code , but the data takes time to reflect in google gauge even though the data is loaded and google gauge will sit set to 0 as initial values ! var url = 'http://san.gotdns.ch:8025/json'; var sensorData; function…
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
1
vote
1 answer

How do I make function to running on background?

I have this code periodically calls the load function which does very load work taking 10sec. Problem is when load function is being executed, it's blocking the main flow. If I send a simple GET request (like a health check) while load is being…
1
vote
1 answer

Reliably clear intervals when switching page on a dynamic app

I load all content inside a div in the index. Some of these pages require starting intervals, and when switching page those intervals keep going, so I created a destroyjs() function which gets overridden by pages that need it, and is also called…
Cârnăciov
  • 1,169
  • 1
  • 12
  • 24
1
vote
0 answers

Ajax request inside setInterval. Abort it and start again

I'm doing ajax request(inside setInterval) inside another ajax , but I have to abort inner ajax after every tick and send it again every interval of time. Why I need setInterval? Because I have to check for an answer from server every second(user…
vladys.bo
  • 730
  • 2
  • 11
  • 34
1
vote
2 answers

setInterval method dilemma

I am trying to implement a slideshow using jQuery I have a button called SlideShow and clicking it would trigger the slide show. I display a set of thumbnails:
kheya
  • 7,546
  • 20
  • 77
  • 109
1
vote
2 answers

Time slider to move automatically using setInterval()

I am trying to make a Mapbox map that would show data chronologically for a given year, and I am trying to make the year be specified automatically in sequence. However, I am having a problem using setInterval to move the time slider in the…
Kristian Vybiral
  • 509
  • 9
  • 20
1
vote
8 answers

how to make an image change multiple times onmouseover

I'm trying to make an image change multiple times so i used setInterval but it doesn't stop HTML: Untitled Document
Joe Zak
  • 15
  • 1
  • 5
1
vote
1 answer

Update Variable Value Outside SetInterval Function

function circleStat(elem1, pvalue, ccolor) { var cx = document.getElementById(elem1); var percentage = 0; var dataval = pvalue; } Hi, I am using this above mentioned code in one of my javascript projects. I would like to increase the…
1
vote
1 answer

Why my setInterval runs only once?

I don't know where is the problem point... (T.T) script is