Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mouse #coordinates #match #canvas #coordinate
ADD COMMENT
Topic
Name
5+3 =