How to display only the first few lines of a div (clamping)?

后端 未结 5 839
南方客
南方客 2020-12-31 10:09

I have a list of divs in which I display the preview of longer documents. The documents use varying font styles. So I don\'t have a constant line height. Here i

5条回答
  •  一个人的身影
    2020-12-31 10:49

    One alternative is to use the dotdotdot jQuery plugin.

    Its used like

    $("div.text_element").dotdotdot({
      ellipsis : "...",
      wrap : "word"
    });
    

    This way, you can just concern yourself with the div dimensions rather than line height or other CSS attributes. Also, it allows you to trigger events to show and hide the hidden text.

提交回复
热议问题