Last active
August 2, 2018 19:36
-
-
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!
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a jQuery plugin version: https://gist.github.com/iamkirkbater/ee9741a02431290682e6