Skip to content

Instantly share code, notes, and snippets.

@ignacioiglesias
Created October 2, 2012 22:53
Show Gist options
  • Save ignacioiglesias/3823822 to your computer and use it in GitHub Desktop.
Save ignacioiglesias/3823822 to your computer and use it in GitHub Desktop.
Shrink text until it fits
// 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);
@ignacioiglesias
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment