开发者

how to check if selected text is inside two lines of text

开发者 https://www.devze.com 2023-02-17 12:04 出处:网络
We开发者_如何学运维 have text in the document and part of the text was selected by user with mouse like:

We开发者_如何学运维 have text in the document and part of the text was selected by user with mouse like:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa****aaaa   aaaaaaaaaaaaaaaaaaaaa  aaaaaaa
a aaaaaaa aaaaaaaaaaaaa aaaa****aaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaa

How can I check if selection is only in one line or in both?

html structure is like:

<div>
   <span> aaaaaaaaaa aaaaaaaaaaa aaa <span> selectedt text </span> </span>
</div>  


Don't know exactly what you are going for, but maybe this could help;

http://www.quirksmode.org/js/events_mouse.html

Under section 'relatedTarget, fromElement, toElement' --> when you give the span elements an id, you could check from which element you started, and in which you ended. Hereby knowing if there was a cross in elements.

I do not think that it's possible to know exactly on which line (on screen) the user starts ends, because of text wrapping, resolution, screen size, font size etc.


That all depends on the size of the users screen/window size


An idea could be to momentarily span one character with a force-layout tag, a span with position:relative, check the height. Then compare it with the entire selections height, retrieved the same way.

0

精彩评论

暂无评论...
验证码 换一张
取 消