Reputation: 335
I am calling many requestAnimationFrames at the same time. How would I cancel all of the requestAnimationFrames such that none are running anymore?
Upvotes: 3
Views: 2804
Reputation: 89254
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);
}
}
Upvotes: 7
Reputation: 7399
window.requestAnimatioFrame(()=>{})
returns a number to be used with window.cancelAnimationFrame(number)
. So, store the numbers in an array, and then iterate over the array canceling the numbers.
Via MDN:
Upvotes: 2