[英]Get mouse position inside an element on event: onDrop
is it possible to calculate somehow position of mouse inside an droppable container.是否有可能以某种方式计算可放置容器内鼠标的 position。 For example mouse cursor is near right border of droppable container.
例如鼠标 cursor 靠近可放置容器的右边界。 I would like to know that position of mouse is to the right, or center, or left relative to the container where I wan't to drop the element
我想知道鼠标的 position 相对于我不想放置元素的容器位于右侧、中心或左侧
<div onDrop="handleDrop">... some content inside </div>
and js和 js
const handleDrop = evt => {
// here I am looking to calculate the mouse position inside the container
}
The event object (evt) that is passed to your handleDrop method already contains the X and Y mouse positions at the moment of drop.传递给您的 handleDrop 方法的事件 object (evt) 已包含放下时的 X 和 Y 鼠标位置。
const handleDrop = evt => {
const mouseX = evt.clientX;
const mouseY = evt.clientY;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.