A.G.
A.G.

Reputation: 23

html5 canvas: fix width/height with fillrect(...)?

when I draw a shape (html5 => canvas) like

context.fillStyle = "rgba(0, 0, 255, 0.5)";
context.fillRect(5, 5, 25, 50);

It's always relative to the size of the canvas element. That is: If I change the size of the canvas element, the "size" of the element adapts to the new canvas size. Do you have any idea how to supress this behaviour (or point me to the right direction)?

Thank you, Andi

Upvotes: 2

Views: 2159

Answers (1)

Laurent T
Laurent T

Reputation: 1098

make sure that you set the width and height of your canvas directly in the HTML like this:

<canvas id="mycanvas" width="..." height="..."></canvas>

Do not set the size of your canvas in CSS or else you will have scaling issues.

Cheers!

Upvotes: 5

Related Questions