question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mouseEvent doesn't have offsetX/offsetY

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
Jarred-Sumnercommented, Jul 7, 2020

As of 2020, this doesn’t seem to need a polyfill. But SyntheticEvent’s MouseEvent doesn’t have offsetX or offsetY

I can submit a PR if you want

https://caniuse.com/#feat=mdn-api_mouseevent_offsetx

image

5reactions
glenjamincommented, May 17, 2016

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found