npm.io
1.0.0 • Published 6 years ago

@codewell/get-canvas-mouse-position

Licence
MIT
Version
1.0.0
Deps
0
Size
3 kB
Vulns
0
Weekly
0

@codewell/get-canvas-mouse-position

Get the position of a mouse on a canvas triggered by an event.

Installation

npm install @codewell/get-canvas-mouse-position

Basic usage

import getCanvasMousePosition from '@codewell/get-canvas-mouse-position':


const handleClick = (event) => {
  const mousePosition = getCanvasMousePosition(event);
  const {x, y} = mousePosition; // The coordinate that was clicked on the canvas
}

return (
  <canvas onClick={handleClick} />
)