React 的 mouseEvent 没有 offsetX/offsetY [英] React's mouseEvent doesn't have offsetX/offsetY

查看:107
本文介绍了React 的 mouseEvent 没有 offsetX/offsetY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试获取相对于元素的点击位置,但事件没有 offsetX.

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?

推荐答案

哦,我明白了.我从 e.nativeEvent.offsetX 得到它.这是正确的方法吗?

Oh, well, I see. I get it from e.nativeEvent.offsetX. Is it right approach?

这篇关于React 的 mouseEvent 没有 offsetX/offsetY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆