如何从 JavaScript 中的 dom 坐标点获取或创建选择或范围?
希望这可以通过调用由浏览器内部代码执行的方法来实现。 给定 dom 坐标中的点 x,y。 (即可以相对于任意节点获取) 在包含我想要有效的文本的元素中,
charIndex = characterUnderPoint(textNode,nodex,nodey);
我想是否有某种功能可以执行
range = xx.creatRange(node,x,y)
或
selection = xx.createSelection(node,x,y)
等等
range.setAnchorToLocation(node,x,y)
。
到目前为止,我找不到任何可以有效实现单击设置插入符号位置时发生的情况的内容。所有方法似乎只采用字符偏移量。
主要是我想要这个,因为通过增加所有字符的范围来测试点是否在其中进行搜索非常慢(可能是二进制搜索,但是)它应该在本机代码中的布局引擎内完成才能快速。
Hopefully this is possible by invoking a method that gets executed by browser internal code.
Given a point x,y in dom coordinates. (that is can get relative to any node)
in an element containing text I want effectively
charIndex = characterUnderPoint(textNode,nodex,nodey);
I figure if there is some sort of facilty to do
range = xx.creatRange(node,x,y)
or
selection = xx.createSelection(node,x,y)
or
range.setAnchorToLocation(node,x,y)
etc.
I can't find anything so far that implements effectively what happens when you click to set the caret position. all the methods seem to only take a character offset.
Mainly I want this because searching by incrementing a range through all the chars to test whether the point is in it is very slow (could be a binary search but) it should be done inside the layout engine in native code to be fast.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有简单的方法可以做到这一点。
Range
不会帮助你。这都是关于节点和偏移量的。There's no easy way to do this.
Range
won't help you. It's all about nodes and offsets.