我尝试获取点击相对于元素的位置,但事件没有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} />
- }
如何获得点击元素的位置?
哦,好吧,我明白了. 我从e.nativeEvent.offsetX得到它.是对的吗?