I am using requestAnimationFrame method to animate a canvas. For unsupported browsers, I am using the polyfill
//I am only posting code for polyfill.
//Actual code uses methods for webkit, mozilla and other browsers too
if(!window.requestAnimationFrame){
requestAnimationFrame = function(callback){
return window.setTimeout(callback, 1000/60);
}
}
My code for animation is
//AnimationCanvas is a canvas with static image of the speedometer
//drawPointerOnCanvas method will draw the pointer
animate = function(context, animationCanvas){
context.drawImage(animationCanvas, 0, 0);
drawPointerOnCanvas();
requestAnimationFrame(this.animate);
}
I want to animate continuously but the polyfill makes the animation random in Android OS 4.1 and 4.2. My requirement is similar to the clock in following MDN link https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_clock
Note: My actual requirement is a speedometer. If I change the speed, it should animate to that point smoothly.
Question: Is there any reliable polyfill or fallbacks available? Because If I use requestAnimationFrame method, animation is smooth. But animation is random if polyfill is used.
Edit: I checked in IE9 by switching through console of IE11, animation is smooth. Could this be related to Memory (RAM) and processor speed in android devices?