[The jQuery] ... beyond the container portion

Ideas:

  1. Obtain the interior region of the container height eleH 

  2. Get inside the text area height pEle 

  3. The cycle of determining the size pEle and eleH

    When pEle> EleH when the end of the text to replace ...

 

 

Code:

<div class="description">
    <span>测试</span>
</div>


/*****
*@paran:超出部分...
*@ele:容器
*@tag:文字标签
**/
ellipsis(".description","span");
function ellipsis(ele,tag){
    var ele = $(ele);
    var eleH = ele.innerHeight();
    var eTag = ele.children(tag);
    while(eTag.innerHeight() > eleH) {
        eTag.text(eTag.html().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
    };
}

/****** 多个 ******/
  $(".description").each(function(){
  var eleH = $(this).innerHeight();
  var pEle =$(this).children("span");
  while (pEle.innerHeight ()> eleh) {
    pEle.text(pEle.html().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
  };
  })

  

 

Guess you like

Origin www.cnblogs.com/SoYang/p/11183393.html