What is EasyAnimationFrame for?
- To make easy javascript loops ( optimized for animations ) using the new RequestAnimationFrame API
- To control and get precisely the framerate of your loops
- To stop and restart any kind of loop without using any javascript timer ( setTimeout or setInterval )
- Thanks to the Paul Irish polyfill it is supported also by the old browsers ( IE7+ )
DEMO
[codepen.io] (http://codepen.io/GianlucaGuarini/full/GlEzv)
USAGE
You must create a new instance of the EAF class setting the loop function, the element you would like to animate (this could be also null), and eventually also the initial framedelay
OPTIONS
loop_Function
: the function you want to loophtml_Element
: { optional, by default is null } the DOM element you are manipulating ,generally it could be an HTML5 canvasinitial_frame_delay
: { optional int, by default is 0} the time expressed in ms EAF should wait each frame before triggering the loop function
var animator = new EAF(loop_Function, html_Element, initial_frame_delay); animator.startAnimation();
#API (public methods)
startAnimation
: it starts the animation with the inital frame delay ( with frame delay equal to 0 you can run your animation to the maximum browser speed).clearAnimation
: it stops immediately the animation.getFrameDelay
: this returns the current frame delayupdateFrameDelay
: it updates the frame delay and could be used also on the flygetFramerate
: It returns the framerate of the current animation