Canvas is stretched when using CSS but normal with “width” / “height” properties

I have 2 canvases, one uses HTML attributes width and height to size it, the other uses CSS: <canvas id=”compteur1″ width=”300″ height=”300″ onmousedown=”compteurClick(this.id);”></canvas> <canvas id=”compteur2″ style=”width: 300px; height: 300px;” onmousedown=”compteurClick(this.id);”></canvas> Compteur1 displays like it should, but not compteur2. The content is drawn using JavaScript on a 300×300 canvas. Why is there a display difference? 9 … Read more

How to change the opacity (alpha, transparency) of an element in a canvas element?

Using the HTML5 <canvas> element, I would like to load an image file (PNG, JPEG, etc.), draw it to the canvas completely transparently, and then fade it in. I have figured out how to load the image and draw it to the canvas, but I don’t know how to change its opacity. Here’s the code … Read more

How do I get the coordinates of a mouse click on a canvas element? [duplicate]

This question already has answers here: Real mouse position in canvas (5 answers) Closed 10 months ago. What’s the simplest way to add a click event handler to a canvas element that will return the x and y coordinates of the click (relative to the canvas element)? No legacy browser compatibility required, Safari, Opera and … Read more