微信动态文字过多显示省略号:中文省略号,英文单词可能被拆分显示省略号

This commit is contained in:
Tim 2016-07-29 17:06:25 +08:00
parent 24a6aabb6b
commit 6342137972
1 changed files with 25 additions and 25 deletions

View File

@ -1,25 +1,25 @@
/**
* Created by Tim on 7/22/16.
*/
//app.directive('ellipsisShow',["$timeout",function(timer){
// return{
// restrict: 'A',
// scope: {},
// link: function(scope, element){
// timer(function() {
// var textSplit = element.text().split(" ");
// var newContent = [];
// element.text("");
// for (var i = 0; i < textSplit.length; i++) {
// newContent = newContent + " " + textSplit[i];
// element.text(newContent);
// if(element[0].scrollHeight >= 100){
// newContent = newContent + " " + textSplit[i+1] + " " + textSplit[i+2] + " " + textSplit[i+3] + " " + textSplit[i+4] + "...";
// element.text(newContent);
// break;
// }
// }
// });
// }
// }
//}]);
/**
* Created by Tim on 7/22/16.
*/
app.directive('ellipsisShow',["$timeout",function(timer){
return{
restrict: 'A',
scope: {},
link: function(scope, element){
timer(function() {
var textSplit = element.text().split("");
var newContent = [];
element.text("");
for (var i = 0; i < textSplit.length; i++) {
newContent = newContent + textSplit[i];
element.text(newContent);
if(element[0].scrollHeight >= 100){
newContent = newContent + textSplit[i+1] + textSplit[i+2] + textSplit[i+3] + textSplit[i+4] + "...";
element.text(newContent);
break;
}
}
});
}
}
}]);