Mobile webapp/game developers often face issue to support the application across multiple mobile devices. This is largely because resolutions of mobile are very different.
Take for example iphone. Following are the resolutions of different versions of iphone
iphone <4 320/480.
iphone 4 640/960
iphone 5 640/1136
So now we need a fluid layout that fit across multiple resolutions. So that application can be supported in multiple mobile devices irrespective of the resolution. However, If the application/game is canvas based we need a technique to resize the canvas. Here, I am going to illustrate an awesome technique found from html5 rocks case study. Where we autoresize the canvas with help of wrapper div. Sounds awesome! right. Lets look into the technique.
Technique to resize canvas to fit all multiple resolutions:
1) Create a container with the position absolute wrapper div
2) Create the canvas tag and make it as the position absolute and define the height and width of the div as 100%
<canvas id=”canvas” width=”600” height=”700”>
position:absolute; (This is optional)
Define the window resize handler to control to update the container div based on the view port height and width
var $canvasWrapper = $(‘#canvasWrapper’);