2016-03-28 71 views
0

我正在使用jquery.dotdotdot截斷傳送帶上Tiles上的冗長文本。截斷有時會間斷地截斷小於預期的結果。 (例如截斷文本至4行,但在某一時刻,只截斷至3行)。使用Jquery.dotdotdot進行間斷截斷

在我的CSS我曾經有4行式是最大高度=行高* 4.

感謝任何迴應。謝謝。 JS:

$(document).ready(function() { 
       EllipsisConfigFunction($(".module-body.dot-ellipsis")); 

    function EllipsisConfigFunction($elements) { 
     $elements.each(function() { 
      var $element = $(this); 
      $element.dotdotdot({ 
       // configuration goes here 
       ellipsis: '... ', 

       /* How to cut off the text/html: 'word'/'letter'/'children' */ 
       wrap: 'word', 

       /* Wrap-option fallback to 'letter' for long words */ 
       fallbackToLetter: true, 

       /* jQuery-selector for the element to keep and put after the ellipsis. */ 
       after: null, 

       /* Whether to update the ellipsis: true/'window' */ 
       watch: true, 

       /* Optionally set a max-height, can be a number or function. 
        If null, the height will be measured. */ 
       height: null, 

       /* Deviation for the height-option. */ 
       tolerance: 0, 

       /* Callback function that is fired after the ellipsis is added, 
        receives two parameters: isTruncated(boolean), orgContent(string). */ 
       callback: function (isTruncated, orgContent) { }, 

       lastCharacter: { 

        /* Remove these characters from the end of the truncated text. */ 
        remove: [' ', ',', ';', '.', '!', '?'], 

        /* Don't add an ellipsis if this array contains 
         the last character of the truncated text. */ 
        noEllipsis: [] 
       } 
      }); 
     }); 
    } 
    }); 

CSS:

.module-body{ 
      max-height: 80px; 
      overflow: hidden; 
      position: relative; 
      text-align: left; 
      line-height:20px; 
     } 

回答

0

既然你還沒有發佈任何代碼的我最好的建議如下:

https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/ 
https://api.jquery.com/jQuery.trim/ 
http://stackoverflow.com/a/4637957/5833940 

看看這些解決您的問題。

bests :)

+0

謝謝@ SG1Asgard。我用代碼更新了問題。感謝您的建議,但我需要一個跨瀏覽器多行省略號。欣賞它。 –