Skip to content

Instantly share code, notes, and snippets.

@iam4x
Last active August 2, 2018 19:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iam4x/5015270 to your computer and use it in GitHub Desktop.
Save iam4x/5015270 to your computer and use it in GitHub Desktop.
I wrote this simple function in CoffeeScript which tests if the text overflow the div and it will decrement his size until it fits!
autoSizeText = ->
elements = $('.resize')
return if elements.length < 0
for el in elements
do (el) ->
resizeText = ->
elNewFontSize = (parseInt($(el).css('font-size'), 10) - 1)
$(el).css('font-size', elNewFontSize)
resizeText() while el.scrollHeight > el.offsetHeight
@iamkirkbater
Copy link

@LinuxRocks2000
Copy link

how to implement?

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