When I listen for mouseover on an element, I get an event fired that has screenX, clientX, pageX and lots of other nice details about where the mouse is relative to the screen and relative to the element that fired the event.
If I just call element.mouseover(), my handler runs, but the mouse location and other properties are all null. I looked at initMouseEvent, but it requires you specify screenX which I don't know.
My question is, how can I get these values without the mouse being over the element or even in the window at all?
In Javascript:
function getScreenCoords(element) {
let rect = element.getBoundingClientRect();
return {
x: window.screenX + rect.left,
y: window.screenY + rect.top
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With