i would like to make a rectangular canvas to simulate a progress bar
but it seems when i set the width and height of a canvas to 100%, it doesn’t really make it as high and as wide as parent
please see example below
http://jsfiddle.net/PQS3A/
Is it even possible to make non-squared canvas?
I don’t want to hardcode the height and width of canvas, because it should change dynamically when viewed in bigger or smaller screen, including mobile devices
Here’s a working example fixing the problems:
http://jsfiddle.net/PQS3A/7/
You had several problems with your example:
<div>does not haveheightorwidthattributes. You need to set those through CSS.position:static, which means that it is NOT the positioning parent of any children. If you want the canvas to be the same size as the div, you must set the div toposition:relative(orabsoluteorfixed).widthandheightattributes on a Canvas specify the number of pixels of data to draw to (like the actual pixels in an image), and are separate from the display size of the canvas. These attributes must be set to integers.The example linked to above uses CSS to set the div size and make it a positioned parent. It creates a JS function (shown below) to both set a canvas to be the same display size as its positioned parent, and then adjusts the internal
widthandheightproperties so that is has the same number of pixels as it shows.