Joined September 2017
·

mtryczak

Thanks for sharing this. I liked it so much, I made a jQuery version:

(function() {
  var elements = $('.resize');
  if(elements.length < 0) {
    return;
  }
  elements.each(function(i, element) {
    while(element.scrollWidth > element.offsetWidth || element.scrollHeight > element.offsetHeight) {
      var newFontSize = (parseFloat($(element).css('font-size').slice(0, -2)) * 0.95) + 'px';
      $(element).css('font-size', newFontSize);
    }
  });
})();

Two embellishments: adjusts for both width and height, and scales back by 95% each time rather than 1 for a tighter fit.
JSFiddle: http://jsfiddle.net/p03ht738/1/

Achievements
1 Karma
0 Total ProTip Views