Skip to content

Instantly share code, notes, and snippets.

@samg
Created May 26, 2009 01:53
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 samg/117849 to your computer and use it in GitHub Desktop.
Save samg/117849 to your computer and use it in GitHub Desktop.
/*
* Scale all textareas dynamically on the page
* Requires JQuery
*/
function scaleTextareas() {
$('textarea').each(function(i, t){
var m = 0;
$($(t).val().split("\n")).each(function(i, s){
m += (s.length/(t.offsetWidth/10)) + 1;
});
t.style.height = Math.floor(m + 2) + 'em';
});
setTimeout(scaleTextareas, 1000);
};
$(document).ready(function(){
scaleTextareas();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment