Skip to content

Instantly share code, notes, and snippets.

@pencilcheck
Forked from iamkirkbater/autoSizr.js
Created July 10, 2017 04:56
Show Gist options
  • Save pencilcheck/efc5ac337f507f6bc516338bc6466696 to your computer and use it in GitHub Desktop.
Save pencilcheck/efc5ac337f507f6bc516338bc6466696 to your computer and use it in GitHub Desktop.
Simple jQuery Plugin that auto resizes text to fill a specific sized div (great for responsive slideshows that utilize large banner text with variable lengths), derived from https://gist.github.com/iam4x/5015270
$.fn.autoSizr = function () {
var el, elements, _i, _len, _results;
elements = $(this);
if (elements.length < 0) {
return;
}
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push((function(el) {
var resizeText, _results1;
resizeText = function() {
var elNewFontSize;
elNewFontSize = (parseInt($(el).css('font-size').slice(0, -2)) - 1) + 'px';
return $(el).css('font-size', elNewFontSize);
};
_results1 = [];
while (el.scrollHeight > el.offsetHeight) {
_results1.push(resizeText());
}
return _results1;
})(el));
}
return $(this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment