js篇
substring: function (str, len, flow) {
if ( ! str) return '';
str = str.toString();
var newStr = "",
strLength = str.replace(/[^\x00-\xff]/g, "**").length,
flow = typeof(flow) == 'undefined' ? '...' : flow;
if (strLength <= len + (strLength % 2 == 0 ? 2 : 1)) return str;
for (var i = 0, newLength = 0, singleChar; i < strLength; i++) {
singleChar = str.charAt(i).toString();
if (singleChar.match(/[^\x00-\xff]/g) != null) newLength += 2;
else newLength++;
if (newLength > len) break;
newStr += singleChar;
}
if (strLength > len) newStr = $.trim(newStr) + flow;
return newStr;
},
css篇
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
white-space: normal !important;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
网友评论