diff --git a/flowtype.js b/flowtype.js index 4a918b0..7829874 100644 --- a/flowtype.js +++ b/flowtype.js @@ -23,22 +23,30 @@ maxFont : 9999, minFont : 1, fontRatio : 35, - lineRatio : 1.45 + lineRatio : 1.45, + useEm: false }, options), // Do the magic math // ================= changes = function(el) { var $el = $(el), - elw = $el.width(), - width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, - fontBase = width / settings.fontRatio, - fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; + unit = 'px', + elw = $el.width(); - $el.css({ - 'font-size' : fontSize + 'px', - 'line-height' : fontSize * settings.lineRatio + 'px' - }); + if (settings.useEm) { + unit = 'em'; + elw = elw / parseFloat($('body').css('font-size')); + } + + var width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw, + fontBase = width / settings.fontRatio, + fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase; + + $el.css({ + 'font-size' : fontSize + unit, + 'line-height' : settings.useEm ? settings.lineRatio + unit : fontSize * settings.lineRatio + unit + }); }; // Make the magic visible