How can I measure how many characters will fit the width of the document?

前端 未结 3 1632
故里飘歌
故里飘歌 2020-12-19 07:42

I need to write, in JavaScript (I am using jQuery), a function that is aware of the number of characters that fit in a line of the browser window. I\'m using a monospace fo

3条回答
  •  执念已碎
    2020-12-19 08:21

    You can get the total width available for the browser with

    window.innerWidth
    

    And then you can get the width of an element with the following method.

    document.getElemenById('elem').clientWidth  
    

提交回复
热议问题