Created
January 30, 2014 16:45
-
-
Save wayferer/8712953 to your computer and use it in GitHub Desktop.
a way to add multi-line ellipsis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.applyEllipsis{ | |
overflow:hidden; | |
position:relative; | |
&:after{ | |
content:'\2026'; | |
position:absolute; | |
right:0; | |
bottom:0; | |
left:0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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