Get mouse position on Canvas

less than 1 minute read

diagram

There are three types of get position of mouse.

  • ScreenX/Y (Systemt Mouse Position)
  • PageX/Y (Content Position ignore scroll)
  • ClientX/Y (Browser Position)

Canvas.addEventListener('click',function(e){
var MousePosition_X = e.PageX;
var MousePosition_Y = e.PageY;

})

How to make canvas full screen?

link

dont forget body have margin and padding too. So you need to add this in <body>:

  <body style="margin:0;padding:0">