| Start |
|---|
| Use requestAnimationFrame() NOT setInterval() for animation loops
Device displays will refresh about 60 times per second so requestAnimationFrame can continuously redraw at about 60 "frames" per second. The eye sees motion at 20-30 frames per second so requestAnimationFrame can easily create the illusion of motion. Notice that requestAnimationFrame is recalled at the end of each animateCircle. This is because each 'requestAnimatonFrameonly requests a single execution of the animation function. Example: simple `requestAnimationFrame To illustrate the advantages of requestAnimationFrame this stackoverflow question has a live demo (opens new window) |
| Animate an image across the Canvas This example loads and animates and image across the Canvas Important Hint! Make sure you give your image time to fully load by using Annotated Code |
| Simple animation with 2D context and requestAnimationFrame This example will show you how to create a simple animation using the canvas and the 2D context. It is assumed you know how to create and add a canvas to the DOM and obtain the context A demo of this example (opens new window) at jsfiddle |
| Animate at a specified interval (add a new rectangle every 1 second) This example adds a new rectangle to the canvas every 1 second (== a 1 second interval) Annotated Code: |
| Animate at a specified time (an animated clock) This example animates a clock showing the seconds as a filled wedge Annotated Code: |
| Don't draw animations in your event handlers (a simple sketch app) During Therefore it makes sense to separate your users input events (like mousemove) from the drawing of your animations. By not drawing in the event handlers, you are not forcing Canvas to try to refresh complex drawings at mouse event speeds. By doing all drawing in Annotated Code: |
| Easing using Robert Penners equations An easing causes some variable to change unevenly over a duration. "variable" must be able to be expressed as a number, and can represent a remarkable variety of things:
"duration" must be able to be expressed as a number and can also be a variety of things:
"unevenly" means that the variable progresses from beginning to ending values unevenly:
Attribution: Robert Penner has created the "gold standard" of easing functions. Cite: https://github.com/danro/jquery-easing/blob/master/jquery.easing.js (opens new window) Example Usage: |
| Animate from [x0,y0] to [x1,y1] Use vectors to calculate incremental [x,y] from [startX,startY] to [endX,endY] Example Code: |
Read Article
https://develop.horje.com/learn/1434/reference