The length of the character is different, how to calculate the width?

character length is different, how to calculate the width

clipboard.png

A width is required for better-scroll initialization, but the length of each string is different. How to calculate the width like it

Mar.06,2021

there has been a similar requirement before, and it was solved like this at first:

JS dynamically generates the element node, then inserts the string into it, and then looks at the width of this element, such as $('.test'). Width () ;

of jQuery ).

later found a simpler solution (a few lines of CSS). (unlike your needs, telling you that the solution is not applicable)

Menu