davatron5000 / FitText.js

A jQuery plugin for inflating web type
http://fittextjs.com
6.76k stars 1.39k forks source link

Better Algo #45

Closed jblemee closed 10 years ago

jblemee commented 11 years ago

Hey,

You can use a better algo based on basic Math :

var fitText = function(parent, width, height) {
       var minCharPerLine = 10;  
       parent.css('font-size', Math.sqrt( (width*height) / (parent.text().length + minCharPerLine )) );
   };

This one will adjust multiline text in the box.

davatron5000 commented 10 years ago

I'm not sure this algorithm works for me b/c we'd have to constantly query for the element's width and height inside a resize() function.

Thanks for the suggestion tho.