javascript - 如何计算鼠标相对于转换后的父级的偏移量
问题描述
如何计算鼠标光标的 offsetX 和 offsetY,相对于正在转换的元素,即使鼠标没有移动?
https://jsfiddle.net/kevin_dorion/usrLd1x3/34/
// this is the value I need to update, even when the mouse is not moving
offsetEl.innerHTML = `x: ${evt.offsetX} y: ${evt.offsetY}`;
如您所见,在 mousemove 上,我得到了 offsetX 和 offsetY 值,这正是我所需要的。但我还需要注意当鼠标不移动时这些值会发生变化。
requestAnimationFrame(animate);
// how do I manually calculate offsetX and offsetY of the mouse cursor relative to the "el" element when the mouse is not moving?
我正在考虑保留最后一个鼠标事件,使用 pageX/pageY 定位一个元素,然后计算它的偏移量,但我无法让它正常工作。
谢谢!
编辑:我正在考虑存储最后一个已知的矩阵/鼠标坐标组合,使用当前矩阵并进行一些插值,但我也无法正确...
解决方案
推荐阅读
- email - 如果服务器停机,发送或接收电子邮件
- apostrophe-cms - 提交权限为“假”的作品未更新到草稿模式。仅在实时模式下可用
- java - 用于 Mac 的预编译 opencv 库
- sqlite - 是否可以在同一个项目中使用 sqlite-net-pcl 和 Akavache 的纯功能?
- ruby-on-rails - RSpec 测试失败
- java - 使用 OkHTTP 客户端下载的二进制文件损坏
- php - WAMP Laravel - 将 API 请求从一个本地站点发送到另一个站点会混淆环境变量
- scala - Vegas (Scala/Spark/Vega) 为每个数据点着色
- c# - 问题创建子任务
- python - 我做错了什么,我该如何解决?