Ellipsis or “truncate with dots” via JavaScript
Written by on August 13th, 2007 in Ajax News.
Steffen Rusitschka wanted a cross-browser text-overflow:ellipsis, so he created it and told us all about it via Ellipsis or “truncate with dots” via JavaScript.
You can see it in action, or download the code. The main ellipsis function:
JAVASCRIPT:
-
-
function ellipsis(e) {
-
var w = e.getWidth() - 10000;
-
var t = e.innerHTML;
-
e.innerHTML = “<span>” + t + “</span>”;
-
e = e.down();
-
while (t.length> 0 && e.getWidth()>= w) {
-
t = t.substr(0, t.length - 1);
-
e.innerHTML = t + “…”;
-
}
-
}
-
Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/143649222/ellipsis-or-%e2%80%9ctruncate-with-dots%e2%80%9d-via-javascript