多行文本超出 JS省略号...

(function($) {
     $(".first-button").on("click", function(event){
          $(".first-text").ellipsis(200);  
          $(this).hide();
     });
})(jQuery);


(function($) {
    
    $.fn.ellipsis = function(charCount) {
        return $(this).each(function() {
            var el = $(this);
           
            var originalText = el.html();
            var originalTextLength = originalText.length;
           
            var tempNode = $(this.cloneNode(true));
           
            var min = 0;
            var max = charCount;
           
            if(charCount < originalTextLength){
                 if (min<=max){
                      var tooltipHTML = null;
                      var trimLocation = (min + max);
                     var text = originalText.substr(0, trimLocation);
                     tempNode.html(text + "…");
                     tooltipHTML = ''+originalText+'';
                     el.after(tooltipHTML);
                 }
                 if (min > max) {
                      //If the max value is greater than the min value, just raise a warning.
                      console.log('character count has to be greater than 0.');
                 }
            }
            else {
                 return false;
            }
            el.html(tempNode.html());
            tempNode.remove();
           
            el.mouseenter(function(){
                    el.parent().find('.ellipsis-tooltip').fadeIn(500);
               });
              
               el.mouseleave(function(){
                    el.parent().find('.ellipsis-tooltip').fadeOut(500);
               });
        });
    };
})(jQuery); 


你可能感兴趣的:(HTMl5,CSS3,JavaScript,HTML5自由者)