Can I attach an onclick event to specific coordinates in a document?

I am wondering if it is possible to bind the onclick event to specific coordinates in the document. Perhaps something similar to the "coordinates of the region" on the image map, which would allow me to create a rectangular or circular region that, when clicked on it, would execute some kind of code. Trying to find a solution all morning, someone with the best coding knowledge can clarify this for me.

+3
source share
3 answers

You can attach a click event to the document itself, and not to any specific element. These events should contain the coordinates of the mouse during the click (clientX and clientY).

, false, , .

$(document).click(function(ev){
    console.log(ev.clientX, ev.clientY)
})

. , , , .

, .

+3

: .

:

, , .

, click, . , , , .

, , .

: , " " , , . , 2d, .

+1

Not unless you have an element that takes these coordinates. Instead, you can bind the event to the element occupying this coordinate space, and simply check the click coordinates in the event object.

0
source

All Articles