I need to make an animation that will change in sequence automatically.
            Asked
            
        
        
            Active
            
        
            Viewed 248 times
        
    -1
            
            
        - 
                    1https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval – j08691 Jan 07 '16 at 18:53
- 
                    2Shouldn't be difficult to find: [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval) or [setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout). – Teemu Jan 07 '16 at 18:53
- 
                    1Your edit just made your post overly broad and useless to the SO community as a whole. You should either revert your edit or update it to that it meets the posting guidelines for SO. – Captain Obvlious Jan 07 '16 at 22:46
- 
                    Agreed with Captain Oblivious. Your original post with code made for a good question. This revised one does not. – theUtherSide Jan 07 '16 at 23:11
3 Answers
4
            
            
        You'll find setInterval helpful for this.
var intervalID = window.setInterval(myFunc, 3000);
function myFunc() {
    //do things here
}
The above code will call myFunc() every 3000 milliseconds, or every 3 seconds.
 
    
    
        Matt Giltaji
        
- 328
- 2
- 10
- 23
2
            
            
        Sounds like a job for setInterval.
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval
To make it change every 3 seconds, you could do something like:
var intervalID = window.setInterval(function, 3000);
This will call the function every 3 seconds. You may need to modify your function to get the behavior desired.
When you want it to stop, do:
window.clearInterval(intervalID);
 
    
    
        Bob Higginson
        
- 9
- 2
 
    
    
        theUtherSide
        
- 3,338
- 4
- 36
- 35
0
            
            
        Take a look at setInterval().  Something along the lines of setInterval(changeLight, 1000) will call the changeLight() function once every second.
 
    
    
        RyanL
        
- 458
- 3
- 14