Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel All Currently Running RequestAnimationFrames

I am calling many requestAnimationFrames at the same time. How would I cancel all of the requestAnimationFrames such that none are running anymore?

like image 270
Zamboni Avatar asked Oct 23 '25 16:10

Zamboni


1 Answers

You can call requestAnimationFrame, store the returned id, and then call cancelAnimationFrame for all positive integers less than that number.

function cancelAllAnimationFrames(){
   var id = window.requestAnimationFrame(function(){});
   while(id--){
     window.cancelAnimationFrame(id);
   }
}
like image 187
Unmitigated Avatar answered Oct 26 '25 04:10

Unmitigated



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!