Skip to content

Instantly share code, notes, and snippets.

@DIYgod
Created April 28, 2017 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DIYgod/98d33aba4c035d85b5b6dc4449f2f080 to your computer and use it in GitHub Desktop.
Save DIYgod/98d33aba4c035d85b5b6dc4449f2f080 to your computer and use it in GitHub Desktop.
ellipsis
const initEllipsis = (ele, height) => {
ele.each(function () {
var $this = $(this);
var text = $this.text();
var lastLength = text.length;
var destination = height;
$this.height('auto');
while ($this.height() > destination && lastLength > 0) {
text = $.trim(text.substr(0, lastLength - 4)) + '\u2026';
$this.text(text);
lastLength = text.length;
}
$this.height('');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment