cancelAnimationFrame and setTimeout

152 Views Asked by At

For the following js code:

let myAnimation;
setTimeout(function(){myAnimation = requestAnimationFrame(turn);}, 500);

Because of scope, the following code does not work to stop the animation:

btnStop.addEventListener('click', function(){cancelAnimationFrame(myAnimation);});

Any suggestion?

0

There are 0 best solutions below