Andrew Hansen
Andrew Hansen

Reputation: 149

Timing nested inside of loops with intervals

I'm trying to fit a repeating time interval within a window.requestAnimationFrame loop but I'm not sure on how I format the syntax to be able to use something like SetInterval() but that didn't seem to work ... anyway to add setInterval() I couldn't get this to work ... any advice?

const renders = function(){
window.requestAnimationFrame(rendres)
setInterval(Dostuff,3000) //right here
}
window.requestAnimationFrame(renders)

Upvotes: 0

Views: 29

Answers (1)

Jason Pelletier
Jason Pelletier

Reputation: 161

const renders = function(){
window.requestAnimationFrame(rendres)
 //do stuff
}
// don't do this
// window.requestAnimationFrame(renders) 

// do this instead
let timer = setInterval(window.requestAnimationFrame(rendres),3000);

Then you can use clearInterval(timer) if you want to remove the timer.

Upvotes: 1

Related Questions