Created
January 18, 2019 09:28
-
-
Save NazarK/7f44785035aeaa9c49e7855ad3af3d18 to your computer and use it in GitHub Desktop.
.text-fit class to fit text into div
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
function text_fit() { | |
$(".text-fit").each(function() { | |
var square = $(this).width()*$(this).height() | |
var chars = $(this).text().trim().length | |
var letter_square = square/chars; | |
var letter_height = Math.sqrt(letter_square)*4/3 | |
$(this).css({"line-height": letter_height+"px", "font-size": letter_height+"px"}) | |
}) | |
} | |
$(document).on("turbolinks:load",text_fit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment