Created
May 13, 2013 09:21
-
-
Save vaicine/5567141 to your computer and use it in GitHub Desktop.
Textfill that actually works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.textfill = function(maxFontSize) { | |
maxFontSize = parseInt(maxFontSize, 10); | |
return this.each(function(){ | |
var ourText = $("a", this), | |
parent = ourText.parent(), | |
maxHeight = parent.height(), | |
maxWidth = parent.width(), | |
fontSize = parseInt(ourText.css("fontSize"), 10), | |
multiplier = maxWidth/ourText.width(), | |
newSize = (fontSize*(multiplier-0.1)); | |
ourText.css( | |
"fontSize", | |
(maxFontSize > 0 && newSize > maxFontSize) ? | |
maxFontSize : | |
newSize | |
); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment