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

来源:互联网 发布:使用u盘安装linux系统 编辑:程序博客网 时间:2024/05/21 01:32
(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 = '<span style="position:relative"><span class="ellipsis-tooltip-theme ellipsis-tooltip" style="margin-top:0.3%">'+originalText+'<span class="ellipsis-tooltip-nub"></span></span ></span >';                     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); 


0 0
原创粉丝点击