Skip to content

Instantly share code, notes, and snippets.

@parasharrajat
Forked from joshwnj/text_overflow.js
Created March 4, 2021 21:09
Show Gist options
  • Select an option

  • Save parasharrajat/cfc0ce67d174507e58e03ebf1fac15be to your computer and use it in GitHub Desktop.

Select an option

Save parasharrajat/cfc0ce67d174507e58e03ebf1fac15be to your computer and use it in GitHub Desktop.

Revisions

  1. @joshwnj joshwnj revised this gist Oct 19, 2010. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions text_overflow.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    var TextOverflow = {
    crop: function(elm) {
    var w = elm.width(), h = elm.height(),
    var w = elm.width(),
    t = elm.text(),
    child;

    elm.html('<span>'+t+'</span>');
    elm.html('<span style="overflow: hidden; white-space: nowrap">'+t+'</span>');
    child = elm.children(":first-child");
    while (t.length > 0 && elm[0].scrollHeight > h) {
    while (t.length > 0 && child.width() > w) {
    t = t.substr(0, t.length - 1);
    child.html(t + '<span class="ellipsis">&hellip;</span>');
    }
    }
    };
    };
  2. @joshwnj joshwnj renamed this gist Oct 19, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @joshwnj joshwnj created this gist Oct 18, 2010.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    var TextOverflow = {
    crop: function(elm) {
    var w = elm.width(), h = elm.height(),
    t = elm.text(),
    child;

    elm.html('<span>'+t+'</span>');
    child = elm.children(":first-child");
    while (t.length > 0 && elm[0].scrollHeight > h) {
    t = t.substr(0, t.length - 1);
    child.html(t + '<span class="ellipsis">&hellip;</span>');
    }
    }
    };