Skip to content

Instantly share code, notes, and snippets.

@wayferer
Created January 30, 2014 16:45
Show Gist options
  • Save wayferer/8712953 to your computer and use it in GitHub Desktop.
Save wayferer/8712953 to your computer and use it in GitHub Desktop.
a way to add multi-line ellipsis
function zAddMulilineEllipsis(el,container,maxHeight){
var tag,tagHeight,tagContentHeight;
tag=el;
tagContentHeight=tag.scrollHeight;
if(maxHeight===undefined){tagHeight=tag.offsetHeight;}else{tagHeight=maxHeight;}
if(tagContentHeight>tagHeight){
if(container=='parent'){zAddClass(tag.parentNode,'applyEllipsis');}
else if(container=='self'){zAddClass(tag,'applyEllipsis');}
}
}
for(i=0;i<zQA('.class p').length;i++){
zAddMulilineEllipsis(zQA('.class p')[i],'parent');
}
for(i=0;i<zQA('.class p').length;i++){
zAddMulilineEllipsis(zQA('.class p')[i],'self');
}
for(i=0;i<zQA('.class h2').length;i++){
zAddMulilineEllipsis(zQA('.class h2')[i],'self',62);
}
.applyEllipsis{
overflow:hidden;
position:relative;
&:after{
content:'\2026';
position:absolute;
right:0;
bottom:0;
left:0;
}
}
function zQ(selector){return document.querySelector(selector);}
function zQA(selector){return document.querySelectorAll(selector);}
function zAddClass(el,className){
if(!((' '+el.className+' ').indexOf(' '+className+' ')>-1)){el.className+=' '+className;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment