I'm kind of stuck with javascript timers. I have been reading the usage of setInterval ,setTimeOut are bad they cause page reflows and repaints,instead use request animation frame
I'm stuck and could not find one resource with a good explanation of how we can do that
I want to know ,how can we replace setinterval with requestanimationframe and settimeout with requestanimationframe
var x = 0;
function SayHi() {
console.log("hi");
console.log(x);
++x
if (x >= 10)
clearInterval(intervalid);
}
var intervalid = setInterval(SayHi, 10);
How can we replace the above code with requestanimationframe and how can we clear it
function greetings(){
console.log("greetings to u");
}
setTimeout(greetings,10);
How can we replace setimeout in the above code with requestanimationframe.
If someone can explain the difference it would be of great help
Thanks