Questions tagged [clearinterval]

The Javascript clearInterval() method clears a timer set with the setInterval() method.

The Javascript clearInterval() method clears a timer set with the setInterval() method.
The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

660 questions
4
votes
2 answers

the api block gets called 2 times, leads in rendering component twice, though conditions are getting checked properly

I am using 3 dynamic variable inside setInterval, in state this.state={ checked: true, currentHash:"some current hash", updating: true } inside componentDidMount, i've done something like this componentDidMount = () => { let timer …
4
votes
1 answer

How to use "clearInterval" in a different if statement to the "setInterval"

I've tried searching for other examples, to fix this issue by myself but I'm fairly new to coding in general and I'm very new to java script so I apologise in advance for any silly mistakes I make. Basically, I am learning javascript and I thought…
4
votes
1 answer

Can clearinterval be called directly with setinterval?

Hello mighty people of the internet :) When playing around a bit with some JS I noticed that I was unable to use the return value of setInterval(function, milliseconds) inside clearInterval(var). Here is a working version of clearing an…
Phy
  • 248
  • 1
  • 8
4
votes
1 answer

Will clearInterval stop queued interval execution

Let's say I have these this myInterval=setInterval(funcA,50); function funcA(){ //Some code that takes longer than 50ms to run } setTimeout(function(){clearInterval(myInterval);},10000} Let's say funcA always takes longer than 50ms to make it…
RSinohara
  • 650
  • 1
  • 4
  • 25
4
votes
3 answers

clearInterval inside callback in ClojureScript

Basically, what I want is to implement this piece of code in ClojureScript: var win = window.open('foo.html', 'windowName'); var timer = setInterval(function() { if(win.closed) { clearInterval(timer); alert('closed'); …
OlegTheCat
  • 4,443
  • 16
  • 24
4
votes
1 answer

Why is my interval clearing only halfway?

I have been working on my first major programming project and so far it has been going pretty well. My goal is to have an animation run until either an event is triggered or 15 seconds have passed. After the animation times out I want to animation…
4
votes
2 answers

Should I call clearInterval() before calling setInterval()

In several places in our code we do something like this: eventGrabber.poller = setInterval(grabEvents, 50); to call the grabEvents method every 50 ms. However, since we do it in more than one place I am wondering if grabEvents is being called more…
Mark M
  • 1,807
  • 2
  • 21
  • 40
4
votes
1 answer

How do I stop the setInterval() function?

How can I stop the interval using the same button I used to start the interval? function slideShow() { 'use strict'; var pics = ['IMG_2135.jpg', 'IMG_2125.jpg', 'IMG_2119.jpg', 'IMG_2118.jpg']; var output =…
ianDONUTS
  • 55
  • 6
3
votes
3 answers

clear interval on hover

have a custom made slider which I would like to stop on hover. I've tried to clear and set the interval on hover but doesn't work properly. It stops only the first time I hover on it then if I move the mouse out and in again it doesn't stop. here's…
Mauro74
  • 4,686
  • 15
  • 58
  • 80
3
votes
1 answer

Store setInterval for clearing later

I'm working on a jQuery plugin that utilises JavaScript intervals. However, when the plugin is called again with the argument running as false, then I want the previous interval called on that particular DOM element to be cleared. Here is some…
user1082754
3
votes
1 answer

Why useRef can be used to store the setInterval reference in react but not a normal variable?

I am trying to understand the useRef hook in React. I have created a simple time in react . The code for which is available below. import { useRef, useState, useEffect } from 'react'; function Parent() { const [count,setCount]=useState(5); …
Ashutosh Kumar
  • 381
  • 2
  • 6
  • 18
3
votes
2 answers

SetInterval does not work well after some actions

When I press Start button it runs function startGame() { invaderId = setInterval(moveInvaders, 1000); } In my game it moves blocks from top to bottom each second. Also I have a laser which shoots and destroy blocks. When you press space…
3
votes
1 answer

Javascript / Toggle / Switch / clearInterval() - not able to clearInterval() when the toggle is switched off

wow, this is my first post! New to programming and coding, this is something of my first projects I work on. I would like to be able to switch a toggle to run a code or to stop it, using the setInterval() for it. But now I am not able to switch it…
3
votes
2 answers

How to ClearInterval in Vuex

I'm trying to clear an interval in my vuex store but it doesn't work. In startCounter I check if my count is equal to 100 to clear the interval in stopCounter with clearInterval(this.myCounterInterval); Here is my code, thank you. import Vue from…
dylanolv
  • 57
  • 6
3
votes
4 answers

How to pause a setInterval countdown timer in react?

I'm trying to build a pomodoro timer with a pause option. There's an analogue clock and a digital timer. My issue is with the digital timer - I can pause it by clearing the interval but do not know how to resume it without starting from the top…
Seif
  • 701
  • 4
  • 13
  • 32
1 2
3
43 44