Skip to content

Instantly share code, notes, and snippets.

@DIYgod
Created March 17, 2016 02:17
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/53967895af30f1f720b2 to your computer and use it in GitHub Desktop.
Save DIYgod/53967895af30f1f720b2 to your computer and use it in GitHub Desktop.
dotdotdot
// dotdotdot
function 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 - 10)) + '\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