Skip to content

Instantly share code, notes, and snippets.

@willbroderick
Last active December 28, 2015 20:49
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 willbroderick/7560228 to your computer and use it in GitHub Desktop.
Save willbroderick/7560228 to your computer and use it in GitHub Desktop.
Scale size of text up/down with % to sit nicely inside parent container. Great for live-type over images/slides. - CURRENTLY DEPENDENT ON A BASE SIZE FROM: {{ settings.adv_page_width }} - how should this be remedied? What's the best way to get a 'default' size? Maybe just a px val in data attribute?
<script>
$(function(){
//Text that scales up/down based on container width
function resizeScalingTextFromColumn() {
$('.scaled-text').each(function(){
var $base = $(this).closest('.scaled-text-base');
var scale = $base.width() / {{ settings.adv_page_width }};
$(this).css('font-size', (scale * 100) + '%');
});
}
$(window).resize(resizeScalingTextFromColumn);
//Note: Use debounced-resize if available
});
</script>
<div class="container">
<div class="column-size-class scaled-text-base">
<h1><span class="scaled-text">I HAVE THE POWEEEEER</span></h1>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment