Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mouse coordinates not match with canvas coordinate

function getCursorPosition(canvas, event) {
    const rect = canvas.getBoundingClientRect()
    const x = event.clientX - rect.left
    const y = event.clientY - rect.top
    console.log("x: " + x + " y: " + y)
}

const canvas = document.querySelector('canvas')
canvas.addEventListener('mousedown', function(e) {
    getCursorPosition(canvas, e)
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: js change root css variable 
Javascript :: if string has number javascript 
Javascript :: change window location javascript 
Javascript :: collision circle 
Javascript :: on load hit click event js 
Javascript :: resolveJsonModule 
Javascript :: angular component between tags 
Javascript :: navigate to route and refresh angular 6 
Javascript :: join array enclosing each value with quotes 
Javascript :: react get screen width 
Javascript :: jquery get class name 
Javascript :: onclick prevent default 
Javascript :: get pods on specific node 
Javascript :: square all numbers in array javascript 
Javascript :: flutter wordspaceing 
Javascript :: mongoose connection nodejs 
Javascript :: shuffle the array 
Javascript :: hide bootstrap modal jquery 
Javascript :: scroll to a tag javascript 
Javascript :: protractor window size 
Javascript :: check textbox is empty in jquery 
Javascript :: search partial string in array javascript 
Javascript :: index export in nodejs 
Javascript :: js document.getelementsbyclassname modify innertext 
Javascript :: javascript reference file two folders up 
Javascript :: mac install jmeter 
Javascript :: Ajax Form All Data Send 
Javascript :: https package node post request 
Javascript :: how to add youtube insta icon to next js 
Javascript :: detect fullscreen mode 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =