Skip to content

Instantly share code, notes, and snippets.

@kitwalker12
Created April 24, 2014 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitwalker12/11266209 to your computer and use it in GitHub Desktop.
Save kitwalker12/11266209 to your computer and use it in GitHub Desktop.
auto resize text
var resizeText = function(el) {
elNewFontSize = (parseInt($(el).css('font-size').slice(0, -2)) - 1) + 'px'
console.log(elNewFontSize);
$(el).css('font-size', elNewFontSize)
};
elements = $('.long-text');
elements.each(function(index, el) {
while(el.scrollWidth > el.offsetWidth) {
resizeText(el);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment