Skip to content

Instantly share code, notes, and snippets.

@dejurin
Created December 30, 2017 17:23
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 dejurin/9bef02be6876e068ee276bee31cb3bcb to your computer and use it in GitHub Desktop.
Save dejurin/9bef02be6876e068ee276bee31cb3bcb to your computer and use it in GitHub Desktop.
Resize font depending on string length
var fontFitResize = function(fit, wrap, step = 0.5) {
var currentSize;
while(fit.offsetWidth < wrap.offsetWidth) {
currentSize = parseFloat(window.getComputedStyle(wrap, null).getPropertyValue('font-size'));
wrap.style.fontSize = (currentSize - step) + 'px';
console.log(wrap.style.fontSize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment