Javascript 在事件处理程序中,鼠标相对于currentTarget的坐标

Javascript 在事件处理程序中,鼠标相对于currentTarget的坐标,javascript,reactjs,Javascript,Reactjs,我有一个外部div,它捕捉onWheel鼠标事件。在处理程序中,我想知道鼠标指针相对于外部div的坐标。例如: constructor() { this.handleWheel = this.handleWheel.bind(this); } handleWheel(event) { // how do I get mouse position relative to the outer div here? } render() { return ( <div on

我有一个外部div,它捕捉
onWheel
鼠标事件。在处理程序中,我想知道鼠标指针相对于外部div的坐标。例如:

constructor() {
  this.handleWheel = this.handleWheel.bind(this);
}

handleWheel(event) {
  // how do I get mouse position relative to the outer div here?
}

render() {
  return (
    <div onWheel={this.handleWheel}>
      ...
      <img src="..." />
      ...
    </div>
  )
}
constructor(){
this.handleWheel=this.handleWheel.bind(this);
}
扶手轮(活动){
//如何获取鼠标相对于外部div的位置?
}
render(){
返回(
...
...
)
}
当我将鼠标指针移到图像上并滚动鼠标滚轮时,
event.target
设置为
,而
event.currentTarget
设置为
。我还可以获取鼠标相对于
事件.target
事件.nativeEvent.offsetX/Y
)的位置,但这对我没有帮助,因为我不知道
相对于
的位置


换句话说,我被卡住了。。。如何获取鼠标相对于已附加处理程序的元素的位置?

我找到了一个可行的解决方案,如果它对某人有帮助,我将在这里发布它。不过我不确定这是否是最好的,所以我希望您能给我一些建议(可能还有更好的解决方案)


棒极了,工作起来很有魅力,我们正在研究如何使用getBoundingClientRect,这里是:)很好的解决方案。在我的例子中,我还需要说明页面滚动的位置。对于船上的其他人:
event\u offsetY=event.pageY-window.pageYOffset-currentTargetRect.top
handleWheel(event) {
  let currentTargetRect = event.currentTarget.getBoundingClientRect();
  const event_offsetX = event.pageX - currentTargetRect.left,
        event_offsetY = event.pageY - currentTargetRect.top;
  //...
}