Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Last active August 29, 2015 14:01
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 jongacnik/fbcdd0e2b1d1049fc43b to your computer and use it in GitHub Desktop.
Save jongacnik/fbcdd0e2b1d1049fc43b to your computer and use it in GitHub Desktop.
Expand Text Modified
/**
* jQuery ExpandText Modified
* Expands or shrinks text (with relative line-height) until it's height hits the edges of it's parent.
* Modified by @amongiants from original script by Michael Botsko (http://www.botsko.net)
*/
(function($){
$.fn.expandText = function(options){
opts = $.extend({ min: 50, max: 500, increment: 2, lineHeight: 1.2 },options);
return this.each(function(){
var me = $(this), max_y = me.height()-(opts.increment*2), span = me.find('.expandedText'), size = opts.min;
me.css({ 'font-size': size, 'line-height': (size * opts.lineHeight) + 'px' });
if(!span.length){
me.wrapInner('<span class="expandedText" />');
span = me.find('span');
}
while(span.height() < max_y){
size += opts.increment;
me.css({ 'font-size': size, 'line-height': (size * opts.lineHeight) + 'px' });
if(size == opts.max) break;
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment