我如何相对于文档/窗口获得用户选择的中心锚点位置(x,y)?
How can I get the user's selection's center anchor point position (x, y) relative to the document/window?
I only know how to get selected nodes using window.getSelection()
. But not the position:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为此目的使用
getBoundingClientRect()
。要获取中心点,请将宽度的一半添加到距屏幕左边缘的水平距离。从文档顶部获得准确的垂直位置。
You can use
getBoundingClientRect()
for this purpose. To get the center point, add the half of width to the horizontal distance from the left edge of the screen.To get the accurate vertical position from the top of the document.