Created
October 2, 2012 22:53
-
-
Save ignacioiglesias/3823822 to your computer and use it in GitHub Desktop.
Shrink text until it fits
This file contains hidden or 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
// It's using Mootools to get/set the font-size. You shouldn't | |
// really need that, I'll change it later. | |
function shrink() { | |
var wrapper = $('wrapper'), | |
text = $('text'), | |
minimumFontSize = 11, | |
fontSize; | |
while(text.offsetWidth > wrapper.offsetWidth) { | |
fontSize = parseInt(text.getStyle('font-size'), 10); | |
if(fontSize > minimumFontSize) | |
text.setStyle('font-size', --fontSize); | |
else break; | |
} | |
} | |
window.addEvent('resize', shrink); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://jsfiddle.net/IgnacioIglesias/vC4GD/7/