简体   繁体   中英

How to get point where the browser wraps the text using Javascript

I have span tags in my html like this

<span>H</span>
<span>e</span>
<span>l</span>
<span>l</span>
<span>o</span>

I have set the width of the div which causes the text to be displayed somewhat like this:

Hel
lo

I want to know where the text wraps or get the last span element in a line. I am sorry if there is not enough description but I am new to stackoverflow. Thanks in advance.

I found the answer myself. Check the offsetTop of each span element in Javascript. When the offsetTop of span element is larger than the previous one, you know that the element is on the next line.

elementOffset = element.offsetTop;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM