I have an image and move it around my web page (JavaScript) like this:
satelliteImage.style.top = coordinates.top + "px"; satelliteImage.style.left = coordinates.left + "px";
Unfortunately, the performance is quite bad in all browsers except Chrome. The bottleneck is rendering speed. I have no hope for IE, but I want to improve Firefox at least. Does anyone have experience with performance of HTML5 Canvas while moving an image, compared to Style change?
If you're using text, you should absolutely stick with CSS if you can get away with it. Canvas ruins the accessibility of your app and disallows users from using a carat or highlighting text or using text to speech.
SVG gives better performance with smaller number of objects or larger surface. Canvas gives better performance with smaller surface or larger number of objects. SVG is vector based and composed of shapes. Canvas is raster based and composed of pixel.
Fast as in faster rendering or faster development? I would say the answer to both is HTML5 canvas. Although it is a fairly new technology, and not even supported by all mainstream browsers yet, it already has much more functionality than you would have using DIVs with normal HTML.
In short, the canvas and WebGL are more performant than the DOM, and with third-party libraries, its ease-of-use is comparable; furthermore, growing browser support for additional web standards have the potential to further boost canvas performance.
I have created equivalent tests to compare frame rates for moving an image via CSS versus drawing it on an HTML canvas. Here are the tests:
And here are the FPS results (see URL for test details):
Image Image Sprite Sprite Browser Canvas CSS Canvas CSS ---------------------------------------------- Safari v5.0.3 59 95 59 89 Firefox v3.6.13 59 95 60 90 Firefox v4.0b8 75 89 78 82 Chrome v8.0 108 230 120 204 iPad, Horiz 17 44 2 14 iPad, Vert 4 75 2 15
As you can see:
Edit: Added tests for moving 20 small animated sprites over a background. The conclusions remain the same.
It's now been over 2 years and I decided to run these tests to see if this still holds true. It does...and it doesn't.
Firefox Desktop and mobile both run CSS animations significantly faster than canvas.
Chrome desktop runs canvas and CSS animations about the same
Chrome Mobile (on Nexus 7) does the exact opposite: canvas runs significantly faster than CSS!
(Using Firefox Android with Nexus 7 and desktop browsers on Linux with 1920x1080 resolution)
Browser/OS Canvas Image CSS IMage Canvas Sprites CSS Sprites ----------- ------------ ---------- -------------- ----------- Firefox 16 56.7fps 215.6 fps 59.2fps 203.6fps Firefox 16 Android 17.1 fps 179.6fps 11.5fps 35.7 Chrome 22 192.3fps 223.5fps 170.1fps 164.3fps Chrome Android 48.3fps 39.9fps 92.8fps 13.1fps
What does everyone else get? Can anyone test IE9, 10 for this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With