Skip to content

Instantly share code, notes, and snippets.

@bdelespierre
Forked from charliepark/hatchshow.js
Last active August 4, 2017 19:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdelespierre/c8046e7d61cf13904004dda8d3a42c0e to your computer and use it in GitHub Desktop.
Save bdelespierre/c8046e7d61cf13904004dda8d3a42c0e to your computer and use it in GitHub Desktop.
A jquery typography plugin.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(function(){
$('.hsjs').hatchShow();
});
(function($){
jQuery.fn.hatchShow = function(){
return $(this).css({
display: 'inline-block',
whiteSpace: 'pre'
}).each(function(){
var parent = $(this).parent(),
fontSize = parseInt($(this).css('font-size').replace('px', '')),
maxWidth = parent.width() - (parent.outerWidth(true) - parent.width());
while ($(this).outerWidth(true) < maxWidth) {
$(this).css('font-size', ++fontSize);
}
while ($(this).outerWidth(true) > maxWidth) {
$(this).css('font-size', --fontSize);
}
})
}
})(jQuery);
</script>
@dnw6
Copy link

dnw6 commented Jan 20, 2017

This was useful, ta

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