Skip to content

Tag: setinterval

countup and countdown loop

I want to count from 3 down to 0 then back up to 3 in a loop. This is kind of “slider” implementation. Everything runs fine until reach the clearInterval from counterry. What am I missing? Answer Use a single loop:

Hold button -> repeat function

I’m trying to achieve something which souldn’t be hard to do, but everything I’ve tried so far hasn’t worked. I have a function that changes a value every time I click a button, and what I want is: when I hold this button, the value should keep changing. This is what I’ve tried a…

Wait until setInterval() is done

I would like to add a small dice-rolling effect to my Javascript code. I think a good way is to use the setInterval() method. My idea was the following code (just for testing): Now I would like to wait for the setInterval until it is done. So I added a setTimeout. This code works quite okay. But in my main

How to start and stop/pause setInterval?

I’m trying to pause and then play a setInterval loop. After I have stopped the loop, the “start” button in my attempt doesn’t seem to work : Is there a working way to do this? Answer The reason you’re seeing this specific problem: JSFiddle wraps your code in a function, so start(…

JavaScript setInterval and `this` solution

I need to access this from my setInterval handler How can I access this.prefs in ajax.onload? Answer The setInterval line should look like this:- Edit: The same principle applies to the ” onload “. In this case its common for the “outer” code to do little, it just sets up the request a…