mouseEvent doesn't have offsetX/offsetY
See original GitHub issueI try get position of click relative to element, but event doesn’t have offsetX.
onClick(e) {
console.log(e.offsetX) // returns undefined
console.log(e.target.offsetX) // returns undefined
}
render() {
return <img src='http://placehold.it/1000x500' onClick={this.onClick} />
}
How I can get position of click in element?
Issue Analytics
- State:
- Created 8 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
React's mouseEvent doesn't have offsetX/offsetY
The event object returned by react is a react SyntheticEvent which wraps the normal JavaScript event object and contains some cross browser conveniences....
Read more >MouseEvent.offsetX - Web APIs - MDN Web Docs
The offsetX read-only property of the MouseEvent interface provides the offset in the X coordinate of the mouse pointer between that event ...
Read more >React's mouseEvent doesn't have offsetX/offsetY-Reactjs
I have found that evt.nativeEvent.offsetX was causing me problems with my component flashing a lot and being sort of weird, I haven't fully...
Read more >How to get the offsetX and offsetY for component pointer events
I try get position of click relative to element, but event doesn't have offsetX.…
Read more >Reactjs – React's mouseEvent doesn't have offsetX/offsetY – iTecNote
I try get position of click relative to element, but event doesn't have offsetX. onClick(e) { console.log(e.offsetX) // returns undefined ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As of 2020, this doesn’t seem to need a polyfill. But
SyntheticEvent
’sMouseEvent
doesn’t haveoffsetX
oroffsetY
I can submit a PR if you want
https://caniuse.com/#feat=mdn-api_mouseevent_offsetx
offsetX/Y
appear to be on the standards track and supported in all major browsers.Any chance of adding them into React - perhaps with a
getBoundingClientRect
shim for browsers which don’t support it?https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX