Insert ellipsis (…) into HTML tag if content too wide

后端 未结 24 3129
名媛妹妹
名媛妹妹 2020-11-22 10:07

I have a webpage with an elastic layout that changes its width if the browser window is resized.

In this layout there are headlines (h2) that will have

24条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 11:10

    Just like @acSlater I couldn't find something for what I needed so I rolled my own. Sharing in case anyone else can use:

    Method:
    ellipsisIfNecessary(mystring,maxlength);
    
    Usage:
    trimmedString = ellipsisIfNecessary(mystring,50);
    
    Code and Demo Link: https://gist.github.com/cemerson/10368014

提交回复
热议问题