While working with the requestAnimationFrame API, I encountered a problem. It might be because the structure I use is wrong, but it seems logical to me.
What I basically do is a very easy background-position manipulation for an infinite falling effect:
( This version is simplified, but demonstrative )
cache.mechanism.snowFall = function(){
cache.snow.position.y ++;
if( cache.snow.position.y > cache.viewport.height ){
cache.snow.position.y -= cache.viewport.height;
}
cache.snow.elem.style.backgroundPosition = "0px " + cache.snow.position.y + "px";
requestAnimationFrame( cache.mechanism.snowFall );
};
Actually, it moves the background position 1px lower with every animation frame. ( Resets when neccessary, to avoid high paint times, and FPS loss )
I initialize it by calling:
cache.mechanism.snowFall();
So, it runs fine, with a very high FPS, but it is not possible to stop it.
cancelAnimationFrame( cache.mechanism.snowFall );
-does nothing, and returns undefined.