1

New to React and JS, please bear with me if this is obvious.

I have a div element that keeps getting updated with more new content. I need to show the line numbers for that scrollable box of text. I know that I can get the scroll position using scrollTop and the total height using scrollHeight, but both of these values are given in pixels.

How do I get the line-height (in pixels) of the text in the div element? I can then use some basic arithmetic to get the line numbers.

Alternately, is there any way to get the scroll position in the unit of line numbers instead of pixels?

magikarp
  • 460
  • 1
  • 8
  • 22
  • To get the line-height you can use `var style = window.getComputedStyle(element [, pseudoElt]);` – Jawad Ahbab Mar 12 '20 at 20:14
  • If you set `line-height` style to the div element, then you can get the line height in pixels. Then you can do some calculations to find the number of line. Refer this https://stackoverflow.com/questions/783899/how-can-i-count-text-lines-inside-an-dom-element-can-i – Aravindan Venkatesan Mar 12 '20 at 20:17

0 Answers0