Last active
August 29, 2015 14:01
-
-
Save jongacnik/fbcdd0e2b1d1049fc43b to your computer and use it in GitHub Desktop.
Expand Text Modified
This file contains hidden or 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
/** | |
* 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