Created
April 28, 2017 02:03
-
-
Save DIYgod/98d33aba4c035d85b5b6dc4449f2f080 to your computer and use it in GitHub Desktop.
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
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