Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mouse coordinates not math with canvas coordinates in js

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 :: generate random numbers in js 
Javascript :: javascript generate random string 
Javascript :: image touchable opacity react native 
Javascript :: js waiting element exist 
Javascript :: js canvas draw polygon 
Javascript :: jquery avoid enter submit 
Javascript :: javascript scroll to bottom 
Javascript :: javascript get utc time 
Javascript :: add quotes to array values javascript 
Javascript :: get only numbers regex javascript 
Javascript :: preview image file upload javascript 
Javascript :: post antiforgerytoken jquery 
Javascript :: for char in string javascript 
Javascript :: ReferenceError: fetch is not defined 
Javascript :: textField space between text flutter 
Javascript :: jquery on click get element 
Javascript :: react native open email client 
Javascript :: kendo dropdownlist value jquery 
Javascript :: scroll to javascript 
Javascript :: javascript round to 2 decimal places 
Javascript :: how to convert string to int a array in javascript 
Javascript :: javascript search in array of strings 
Javascript :: onclick go to url 
Javascript :: sanitise string js 
Javascript :: js reverse array loop 
Javascript :: enable select jquery 
Javascript :: js number validation 
Javascript :: check if string is valid json dart 
Javascript :: brand icons in next js 
Javascript :: translatex in javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =