在事件:onDrop时获取鼠标在元素中的位置



是否有可能以某种方式计算鼠标在可放容器中的位置?例如,鼠标光标靠近可放容器的右边界。我想知道鼠标的位置相对于我不想放置元素

的容器是在右边,中间还是左边
<div onDrop="handleDrop">... some content inside </div>

和js

const handleDrop = evt => {
// here I am looking to calculate the mouse position inside the container
}

传递给handleDrop方法的事件对象(evt)已经包含了鼠标下落时刻的X和Y位置。

const handleDrop = evt => {
const mouseX = evt.clientX;
const mouseY = evt.clientY;
}

最新更新