Skip to content

Instantly share code, notes, and snippets.

@Boorj
Created October 17, 2016 05:04
Show Gist options
  • Select an option

  • Save Boorj/1e4402eccddd55bb653db57f43102e73 to your computer and use it in GitHub Desktop.

Select an option

Save Boorj/1e4402eccddd55bb653db57f43102e73 to your computer and use it in GitHub Desktop.
Assigns auto height fitting for any <textarea/> on page
//requires _.throttle and jquery, but dependency could be removed
(function() {
var AutoGrowTextArea;
AutoGrowTextArea = function(e) {
var textField;
textField = e.target;
if (textField.clientHeight < textField.scrollHeight) {
textField.style.height = textField.scrollHeight + 'px';
if (textField.clientHeight < textField.scrollHeight) {
textField.style.height = textField.scrollHeight * 2 - textField.clientHeight + 'px';
}
}
};
return $('textarea').keyup(_.throttle(AutoGrowTextArea, 900));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment