HTML canvas resize and mouse coordinates

If you are using canvas with predefined width and height you probably know that resizing the window and canvas result in size not always the same as the screen.

This is annoying especially for retrieving mouse coordinates exactly matching with the canvas size instead of the window size.

Here is an idea on how to stretch the canvas and still keep the coordinates correct for the original dimension:

Facebooktwitterredditpinterestlinkedinmail