如何用不包括在区域内的元素计数来实现省略。
示例
我的名字有苹果,芒果,稻草,荔枝,橘子,葡萄
我的容器是100 is宽,根据宽度的不同,只能携带很少的名称。
结果应该是
苹果芒果稻草..。+3
或
苹果芒果..。+4如果(宽度较小)
如何用角度来实现这件事。
发布于 2016-01-07 20:06:31
var ellipsisCreator = function(array) {
var arraySize = [],
size = 0,
stopCounter = 0;
scope.toolTiptext = null;
scope.visibleText = null;
scope.remaining = 0;
for(var i=0;i<array.length;i++){
var e=document.createElement('span');
document.body.appendChild(e);
e.style.fontSize = scope.fontsize+'px';
e.setAttribute("class", "posAbs");
e.innerHTML = array[i];
arraySize.push(e.offsetWidth+5);
e.remove();
if(size + arraySize[i] >= scope.length){
stopCounter = i-1;
break;
}else{
size = size + arraySize[i];
stopCounter = i;
}
}
scope.visibleText = array.slice(0,stopCounter+1).join(', ');
if(stopCounter<array.length-1){
scope.toolTiptext = array.slice(stopCounter+1,array.length).join(', ');
scope.remaining = (array.length-1) - stopCounter;
}
};https://stackoverflow.com/questions/34660309
复制相似问题