【发布时间】:2019-03-11 08:44:32
【问题描述】:
如何从 HTML 元素中获取相对于屏幕的 x,y 坐标?
我正在使用来自getBoundingClientRect() 的 x,y 如下所示,但正如您在打击图像中看到的那样,如果我使用将光标移动到这个 x,y 位置,则光标位于 0 和 + 按钮之间的中间,而不是5 按钮,即目标按钮。
我错过了什么?
JS代码:
var e = document.querySelector('input[id=five]');"
var r = e.getBoundingClientRect();
var x = r.x;
var y = r.y;
MoveMouseTo(x,y); // imaginary call, the real cursor move is done by C# but I can share the code, as needed.
图片:
注意:如果此附加信息可能有帮助,它是一个带有嵌入式浏览器的 C# 应用程序。
【问题讨论】:
标签: javascript c# coordinates mouse-coordinates