javascript - Calculate text size before inserted to DOM -
is possible calculate height of text before inserted dom? width of div container known, need way calculate height before inserted. heights of 1 line of text known (css), height calculated multiplying height of 1 line amount of lines, question if possible calculated before it's dom.
since question explicitly requires text not inserted dom precludes used method of inserting outside viewport , measuring there.
an alternative approach: canvas 2d rendering context's measuretext function can used determine width if know styling (font width) apply in advance.
some advanced css rules such letter-spacing
may make results inaccurate.
Comments
Post a Comment