Last active
January 25, 2019 09:20
-
-
Save Patrick64/b5abab784ba2afb99509c2e7501af9fd to your computer and use it in GitHub Desktop.
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
/** | |
* Set font size so the text fits the width of the container | |
*/ | |
function setupTitleTextFill(container, textElement) { | |
// make element inline block and wrap a div so it still does a line break | |
$(container + " " + textElement).css("display","inline-block").wrap('<div class="title-text-fill-wrapper"></div>'); | |
resizeTitleTextFill(container, textElement); | |
$(window).resize(function() { | |
resizeTitleTextFill(container, textElement); | |
}); | |
} | |
function resizeTitleTextFill(container, textElement) { | |
var maxFontSize = 80; //px | |
var minFontSize = 25; //px | |
$(container).each(function() { | |
var $heading = $(this).find(textElement); | |
$heading.css("font-size","10px"); | |
var maxWidth = $(this).width(); | |
var widthAt10px = $heading.width(); | |
var newFontSize = Math.min(Math.max(10 * (maxWidth / widthAt10px),minFontSize),maxFontSize); | |
$heading.css("font-size",newFontSize + "px"); | |
}) | |
} | |
$( document ).ready(function() { | |
setupTitleTextFill('.title-banner-content','h3'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment